Skip to content

Commit

Permalink
Add the first Issue annotation test
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 5, 2024
1 parent eec2f50 commit c6c6ea7
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/test/java/com/epam/reportportal/junit5/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.epam.reportportal.junit5;

import com.epam.reportportal.junit5.features.basic.TestFailure;
import com.epam.reportportal.junit5.features.TestFailure;
import com.epam.reportportal.junit5.util.TestUtils;
import com.epam.reportportal.listeners.ItemStatus;
import com.epam.reportportal.service.Launch;
Expand Down
83 changes: 83 additions & 0 deletions src/test/java/com/epam/reportportal/junit5/IssueReportingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.junit5;

import com.epam.reportportal.junit5.features.issue.SimpleIssueTest;
import com.epam.reportportal.junit5.util.TestUtils;
import com.epam.reportportal.listeners.ItemStatus;
import com.epam.reportportal.service.Launch;
import com.epam.reportportal.util.test.CommonUtils;
import com.epam.ta.reportportal.ws.model.FinishTestItemRQ;
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
import com.epam.ta.reportportal.ws.model.issue.Issue;
import io.reactivex.Maybe;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.mockito.ArgumentCaptor;
import org.mockito.stubbing.Answer;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class IssueReportingTest {
public static class TestExtension extends ReportPortalExtension {
static Launch LAUNCH;

@Override
protected Launch getLaunch(ExtensionContext context) {
return LAUNCH;
}
}

private final String SUITE_ID = CommonUtils.namedId("suite_");
private final Maybe<String> SUITE_MAYBE = Maybe.just(SUITE_ID);
private final String STEP_ID = CommonUtils.namedId("step_");
private final Maybe<String> STEP_MAYBE = Maybe.just(STEP_ID);

@BeforeEach
public void setupMock() {
Launch launch = mock(Launch.class);
IssueReportingTest.TestExtension.LAUNCH = launch;
when(launch.startTestItem(any())).thenAnswer((Answer<Maybe<String>>) invocation -> SUITE_MAYBE);
when(launch.startTestItem(same(SUITE_MAYBE), any())).thenAnswer((Answer<Maybe<String>>) invocation -> STEP_MAYBE);
when(launch.finishTestItem(any(),
any()
)).thenAnswer((Answer<Maybe<OperationCompletionRS>>) invocation -> Maybe.just(new OperationCompletionRS("OK")));
}

@Test
public void verify_simple_test_failure() {
TestUtils.runClasses(SimpleIssueTest.class);

Launch launch = IssueReportingTest.TestExtension.LAUNCH;
ArgumentCaptor<FinishTestItemRQ> testCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
verify(launch).finishTestItem(same(STEP_MAYBE), testCaptor.capture());

FinishTestItemRQ finishTestItemRQ = testCaptor.getValue();
assertThat(finishTestItemRQ.getStatus(), equalTo(ItemStatus.FAILED.name()));
assertThat(finishTestItemRQ.getIssue(), notNullValue());
Issue issue = finishTestItemRQ.getIssue();
assertThat(issue.getIssueType(), equalTo("pb001"));
assertThat(issue.getComment(), equalTo(SimpleIssueTest.FAILURE_MESSAGE));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2022 EPAM Systems
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.epam.reportportal.junit5.features.basic;
package com.epam.reportportal.junit5.features;

import com.epam.reportportal.junit5.BasicTest;
import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import com.epam.reportportal.junit5.DisplayNameTest;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.stream.Stream;

import static org.junit.jupiter.api.DynamicTest.dynamicTest;

@ExtendWith(DisplayNameTest.TestExtension.class)
public class DynamicIssueTest {
public static final String FAILURE_MESSAGE = "This test is expected to fail";

@TestFactory
@Issue(value = "ab001", comment = FAILURE_MESSAGE)
Stream<DynamicTest> testForTestFactory() {
return Stream.of(dynamicTest("My dynamic test", () -> {
throw new IllegalStateException(FAILURE_MESSAGE);
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import com.epam.reportportal.annotations.TestFilter;
import com.epam.reportportal.annotations.TestParamFilter;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@ExtendWith(com.epam.reportportal.junit5.ReportPortalExtension.class)
public class ParameterizedWithOneIssueTest {

public static final String FAILURE_MESSAGE = "This parameterized test is expected to fail: ";

@ParameterizedTest
@ValueSource(booleans = { true, false })
@Issue(value = "ab001", comment = "This test is expected to fail", filter = @TestFilter(param = {
@TestParamFilter(valueStartsWith = "true") }))
public void failureTest(boolean param) {
throw new IllegalStateException(FAILURE_MESSAGE + param);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import com.epam.reportportal.annotations.TestFilter;
import com.epam.reportportal.annotations.TestParamFilter;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@ExtendWith(com.epam.reportportal.junit5.ReportPortalExtension.class)
public class ParameterizedWithTwoIssueTest {

public static final String FAILURE_MESSAGE = "This parameterized test is expected to fail: ";
public static final String ISSUE_MESSAGE = "This test is expected to fail";

@ParameterizedTest
@ValueSource(booleans = { true, false })
@Issue(value = "ab001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "true") }))
@Issue(value = "pb001", comment = ISSUE_MESSAGE, filter = @TestFilter(param = { @TestParamFilter(valueStartsWith = "false") }))
public void failureTest(boolean param) {
throw new IllegalStateException(FAILURE_MESSAGE + param);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import com.epam.reportportal.junit5.IssueReportingTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(IssueReportingTest.TestExtension.class)
public class SimpleIssueTest {

public static final String FAILURE_MESSAGE = "This test is expected to fail";

@Test
@Issue(value = "pb001", comment = FAILURE_MESSAGE)
public void failureTest() {
throw new IllegalStateException(FAILURE_MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(com.epam.reportportal.junit5.ReportPortalExtension.class)
public class SimpleTwoIssuesTest {

public static final String FAILURE_MESSAGE = "This test is expected to fail";

@Test
@Issue(value = "pb001", comment = FAILURE_MESSAGE)
@Issue(value = "ab001", comment = FAILURE_MESSAGE)
public void failureTest() {
throw new IllegalStateException(FAILURE_MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import com.epam.reportportal.junit5.DisplayNameTest;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.stream.Stream;

import static org.junit.jupiter.api.DynamicTest.dynamicTest;

@ExtendWith(DisplayNameTest.TestExtension.class)
public class TwoDynamicIssueTest {
public static final String FAILURE_MESSAGE = "This test is expected to fail";

@TestFactory
@Issue(value = "ab001", comment = FAILURE_MESSAGE)
Stream<DynamicTest> testForTestFactory() {
return Stream.of(dynamicTest("My dynamic test", () -> {
throw new IllegalStateException(FAILURE_MESSAGE);
}), dynamicTest("My dynamic test 2", () -> {
throw new IllegalStateException(FAILURE_MESSAGE);
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.epam.reportportal.junit5.features.issue;

import com.epam.reportportal.annotations.Issue;
import com.epam.reportportal.annotations.TestFilter;
import com.epam.reportportal.annotations.TestNameFilter;
import com.epam.reportportal.junit5.DisplayNameTest;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.stream.Stream;

import static org.junit.jupiter.api.DynamicTest.dynamicTest;

@ExtendWith(DisplayNameTest.TestExtension.class)
public class TwoDynamicTwoIssueTest {
public static final String FAILURE_MESSAGE = "This test is expected to fail";

@TestFactory
@Issue(value = "ab001", comment = FAILURE_MESSAGE, filter = {@TestFilter(name = @TestNameFilter(endsWith = "test")) })
@Issue(value = "pb001", comment = FAILURE_MESSAGE, filter = {@TestFilter(name = @TestNameFilter(contains = "test 2")) })
Stream<DynamicTest> testForTestFactory() {
return Stream.of(dynamicTest("My dynamic test", () -> {
throw new IllegalStateException(FAILURE_MESSAGE);
}), dynamicTest("My dynamic test 2", () -> {
throw new IllegalStateException(FAILURE_MESSAGE);
}));
}
}

0 comments on commit c6c6ea7

Please sign in to comment.