Skip to content

Commit 930c502

Browse files
committed
Versions promote
1 parent 06b0199 commit 930c502

File tree

6 files changed

+130
-9
lines changed

6 files changed

+130
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- Class level `@Attributes` annotation support
6+
### Changed
7+
- Version promoted to stable release
8+
- Client version updated on [5.1.0](https://github.com/reportportal/client-java/releases/tag/5.1.0)
49

510
## [5.1.0-RC-4]
611
### Added

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ repositories {
2828
}
2929

3030
dependencies {
31-
api 'com.epam.reportportal:client-java:5.1.0-RC-12'
31+
api 'com.epam.reportportal:client-java:5.1.0'
3232
api 'com.epam.reportportal:commons-model:5.0.0'
33-
api 'com.nordstrom.tools:junit-foundation:15.3.0'
33+
api 'com.nordstrom.tools:junit-foundation:15.3.4'
3434
api 'com.google.code.findbugs:jsr305:3.0.2'
3535

3636
implementation 'org.slf4j:slf4j-api:1.7.25'

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=5.1.0-RC-5-SNAPSHOT
1+
version=5.1.0-SNAPSHOT
22
description=ReportPortal JUnit 4 client
33
junit5_version=5.6.3
44
junit5_runner_version=1.6.3

src/main/java/com/epam/reportportal/junit/ReportPortalListener.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import javax.annotation.Nonnull;
5555
import javax.annotation.Nullable;
5656
import java.lang.annotation.Annotation;
57+
import java.lang.reflect.AnnotatedElement;
5758
import java.lang.reflect.Constructor;
5859
import java.lang.reflect.Method;
5960
import java.util.*;
@@ -393,8 +394,7 @@ protected void finishTest(@Nonnull final AtomicTest testContext) {
393394
if (ItemStatus.FAILED == theoryStatus) {
394395
sendReportPortalMsg(l.getItemId(), LogLevel.ERROR, context.getTestThrowable(key));
395396
}
396-
stopTestMethod(
397-
l,
397+
stopTestMethod(l,
398398
method,
399399
buildFinishStepRq(runner, method, callable, theoryStatus == null ? ItemStatus.PASSED : theoryStatus)
400400
);
@@ -1031,6 +1031,12 @@ protected String getCodeRef(@Nonnull final FrameworkMethod frameworkMethod) {
10311031
return TestCaseIdUtils.getCodeRef(frameworkMethod.getMethod());
10321032
}
10331033

1034+
@Nonnull
1035+
private Set<ItemAttributesRQ> getAttributes(@Nonnull final AnnotatedElement annotatedElement) {
1036+
return ofNullable(annotatedElement.getAnnotation(Attributes.class)).map(AttributeParser::retrieveAttributes)
1037+
.orElse(Collections.emptySet());
1038+
}
1039+
10341040
/**
10351041
* Extract and returns static attributes of a test class (set with {@link Category} annotation)
10361042
*
@@ -1039,8 +1045,12 @@ protected String getCodeRef(@Nonnull final FrameworkMethod frameworkMethod) {
10391045
*/
10401046
@Nonnull
10411047
protected Set<ItemAttributesRQ> getAttributes(@Nonnull final TestClass testClass) {
1042-
return ofNullable(testClass.getAnnotation(Category.class)).map(a -> Arrays.stream(a.value())
1043-
.map(c -> new ItemAttributesRQ(null, c.getSimpleName()))).orElse(Stream.empty()).collect(Collectors.toSet());
1048+
Stream<ItemAttributesRQ> categories = ofNullable(testClass.getAnnotation(Category.class)).map(a -> Arrays.stream(a.value())
1049+
.map(c -> new ItemAttributesRQ(null, c.getSimpleName()))).orElse(Stream.empty());
1050+
Stream<ItemAttributesRQ> attributes = ofNullable(testClass.getJavaClass()).map(this::getAttributes)
1051+
.map(Set::stream)
1052+
.orElse(Stream.empty());
1053+
return Stream.concat(categories, attributes).collect(Collectors.toSet());
10441054
}
10451055

10461056
/**
@@ -1053,8 +1063,9 @@ protected Set<ItemAttributesRQ> getAttributes(@Nonnull final TestClass testClass
10531063
protected Set<ItemAttributesRQ> getAttributes(@Nonnull final FrameworkMethod frameworkMethod) {
10541064
Stream<ItemAttributesRQ> categories = ofNullable(frameworkMethod.getAnnotation(Category.class)).map(a -> Arrays.stream(a.value())
10551065
.map(c -> new ItemAttributesRQ(null, c.getSimpleName()))).orElse(Stream.empty());
1056-
Stream<ItemAttributesRQ> attributes = ofNullable(frameworkMethod.getMethod()).flatMap(m -> ofNullable(m.getAnnotation(Attributes.class)).map(
1057-
a -> AttributeParser.retrieveAttributes(a).stream())).orElse(Stream.empty());
1066+
Stream<ItemAttributesRQ> attributes = ofNullable(frameworkMethod.getMethod()).map(this::getAttributes)
1067+
.orElse(Collections.emptySet())
1068+
.stream();
10581069
return Stream.concat(categories, attributes).collect(Collectors.toSet());
10591070
}
10601071

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2020 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.epam.reportportal.junit.attribute;
18+
19+
import com.epam.reportportal.junit.ReportPortalListener;
20+
import com.epam.reportportal.junit.features.attribute.ClassLevelKeyValueAttributeTest;
21+
import com.epam.reportportal.junit.utils.TestUtils;
22+
import com.epam.reportportal.service.ReportPortal;
23+
import com.epam.reportportal.service.ReportPortalClient;
24+
import com.epam.reportportal.util.test.CommonUtils;
25+
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
26+
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.mockito.ArgumentCaptor;
30+
import org.mockito.ArgumentMatchers;
31+
32+
import static com.epam.reportportal.junit.utils.TestUtils.PROCESSING_TIMEOUT;
33+
import static org.hamcrest.MatcherAssert.assertThat;
34+
import static org.hamcrest.Matchers.*;
35+
import static org.mockito.Mockito.*;
36+
37+
public class ClassKvAttributeTest {
38+
39+
private final String classId = CommonUtils.namedId("class_");
40+
private final String methodId = CommonUtils.namedId("method_");
41+
42+
private final ReportPortalClient client = mock(ReportPortalClient.class);
43+
44+
@BeforeEach
45+
public void setupMock() {
46+
TestUtils.mockLaunch(client, null, null, classId, methodId);
47+
TestUtils.mockBatchLogging(client);
48+
ReportPortalListener.setReportPortal(ReportPortal.create(client, TestUtils.standardParameters(), TestUtils.testExecutor()));
49+
}
50+
51+
@Test
52+
public void verify_static_attribute_bypass() {
53+
TestUtils.runClasses(ClassLevelKeyValueAttributeTest.class);
54+
55+
ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class);
56+
verify(client, timeout(PROCESSING_TIMEOUT)).startTestItem(
57+
ArgumentMatchers.startsWith(TestUtils.ROOT_SUITE_PREFIX),
58+
captor.capture()
59+
);
60+
61+
StartTestItemRQ suiteRq = captor.getValue();
62+
assertThat(suiteRq.getAttributes(), allOf(notNullValue(), hasSize(1)));
63+
ItemAttributesRQ attribute = suiteRq.getAttributes().iterator().next();
64+
assertThat(attribute.getKey(), equalTo(ClassLevelKeyValueAttributeTest.KEY));
65+
assertThat(attribute.getValue(), equalTo(ClassLevelKeyValueAttributeTest.VALUE));
66+
67+
captor = ArgumentCaptor.forClass(StartTestItemRQ.class);
68+
verify(client, timeout(PROCESSING_TIMEOUT)).startTestItem(same(classId), captor.capture());
69+
StartTestItemRQ testRq = captor.getValue();
70+
assertThat(testRq.getAttributes(), anyOf(nullValue(), emptyIterable()));
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2020 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.epam.reportportal.junit.features.attribute;
18+
19+
import com.epam.reportportal.annotations.attribute.Attribute;
20+
import com.epam.reportportal.annotations.attribute.Attributes;
21+
import org.junit.Test;
22+
23+
@Attributes(attributes = { @Attribute(key = ClassLevelKeyValueAttributeTest.KEY, value = ClassLevelKeyValueAttributeTest.VALUE) })
24+
public class ClassLevelKeyValueAttributeTest {
25+
26+
public static final String KEY = "attribute_test_key";
27+
public static final String VALUE = "attribute_test_value";
28+
29+
@Test
30+
public void first() {
31+
System.out.println("Test class: " + getClass().getCanonicalName());
32+
}
33+
}

0 commit comments

Comments
 (0)