Search in sources :

Example 1 with StartTestItemRQ

use of com.epam.ta.reportportal.ws.model.StartTestItemRQ in project agent-java-testNG by reportportal.

the class AttributeTest method verify_class_level_attributes_bypass.

@Test
public void verify_class_level_attributes_bypass() {
    TestUtils.runTests(Collections.singletonList(TestReportPortalListener.class), ClassLevelAttributesTest.class);
    // Start parent suite
    verify(launch).startTestItem(any());
    ArgumentCaptor<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class);
    // Start test and step
    verify(launch, times(2)).startTestItem(any(), captor.capture());
    StartTestItemRQ testRequest = extractRequest(captor, "test");
    assertThat(testRequest.getAttributes(), hasSize(1));
    ItemAttributesRQ attribute = testRequest.getAttributes().iterator().next();
    assertThat(attribute.getKey(), equalTo(ClassLevelAttributesTest.KEY));
    assertThat(attribute.getValue(), equalTo(ClassLevelAttributesTest.VALUE));
}
Also used : ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) ClassLevelAttributesTest(com.epam.reportportal.testng.integration.feature.attributes.ClassLevelAttributesTest) Test(org.junit.jupiter.api.Test)

Example 2 with StartTestItemRQ

use of com.epam.ta.reportportal.ws.model.StartTestItemRQ in project agent-java-testNG by reportportal.

the class BuildStepTest method testRetryFlagPositive.

@Test
public void testRetryFlagPositive() {
    when(testResult.getMethod()).thenReturn(testNGMethod);
    when(testResult.wasRetried()).thenReturn(true);
    when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
    when(testNGMethod.isTest()).thenReturn(true);
    StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
    assertThat("Incorrect retry flag", rq.isRetry(), is(true));
}
Also used : StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Example 3 with StartTestItemRQ

use of com.epam.ta.reportportal.ws.model.StartTestItemRQ in project agent-java-testNG by reportportal.

the class BuildStepTest method testCaseId_fromAnnotation.

@Test
public void testCaseId_fromAnnotation() {
    when(testResult.getMethod()).thenReturn(testNGMethod);
    when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
    when(testNGMethod.isTest()).thenReturn(true);
    Optional<Method> methodOptional = Arrays.stream(TestMethodsExamples.class.getDeclaredMethods()).filter(it -> it.getName().equals("testCaseId")).findFirst();
    assertTrue(methodOptional.isPresent());
    String expectedCodeRef = "com.test.BuildStepTest.codeRefTest";
    when(constructorOrMethod.getMethod()).thenReturn(methodOptional.get());
    when(testResult.getMethod().getQualifiedName()).thenReturn(expectedCodeRef);
    StartTestItemRQ request = testNGService.buildStartStepRq(testResult);
    assertEquals(expectedCodeRef, request.getCodeRef());
    assertEquals("test-case-id", request.getTestCaseId());
}
Also used : Ignore(org.testng.annotations.Ignore) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) DataProvider(org.testng.annotations.DataProvider) TestCaseIdKey(com.epam.reportportal.annotations.TestCaseIdKey) Launch(com.epam.reportportal.service.Launch) Mock(org.mockito.Mock) TestCaseId(com.epam.reportportal.annotations.TestCaseId) ITestResult(org.testng.ITestResult) Constants(com.epam.reportportal.testng.Constants) FinishTestItemRQ(com.epam.ta.reportportal.ws.model.FinishTestItemRQ) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Matchers.nullValue(org.hamcrest.Matchers.nullValue) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Method(java.lang.reflect.Method) MemoizingSupplier(com.epam.reportportal.utils.MemoizingSupplier) ItemStatus(com.epam.reportportal.listeners.ItemStatus) Mockito.when(org.mockito.Mockito.when) ParameterKey(com.epam.reportportal.annotations.ParameterKey) Test(org.junit.jupiter.api.Test) UniqueID(com.epam.reportportal.annotations.UniqueID) ITestNGMethod(org.testng.ITestNGMethod) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Parameters(org.testng.annotations.Parameters) Matchers.is(org.hamcrest.Matchers.is) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) Method(java.lang.reflect.Method) ITestNGMethod(org.testng.ITestNGMethod) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Example 4 with StartTestItemRQ

use of com.epam.ta.reportportal.ws.model.StartTestItemRQ in project agent-java-testNG by reportportal.

the class BuildStepTest method testMethodName.

@Test
public void testMethodName() {
    when(testResult.getMethod()).thenReturn(testNGMethod);
    when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
    when(testNGMethod.isTest()).thenReturn(true);
    when(testNGMethod.getMethodName()).thenReturn(DEFAULT_NAME);
    StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
    assertThat("Incorrect test item name", rq.getName(), is(DEFAULT_NAME));
}
Also used : StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Example 5 with StartTestItemRQ

use of com.epam.ta.reportportal.ws.model.StartTestItemRQ in project agent-java-testNG by reportportal.

the class BuildStepTest method testParameters.

@Test
public void testParameters() {
    when(testResult.getMethod()).thenReturn(testNGMethod);
    when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod);
    when(testNGMethod.isTest()).thenReturn(true);
    Method[] methods = TestMethodsExamples.class.getDeclaredMethods();
    Method method = null;
    for (Method m : methods) {
        if (m.getName().contains("parametersAnnotation")) {
            method = m;
        }
    }
    when(constructorOrMethod.getMethod()).thenReturn(method);
    when(testResult.getParameters()).thenReturn(new Object[] { "param_0", "param_1" });
    StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
    assertThat("Incorrect parameter key", rq.getParameters().get(0).getKey(), is("message_0"));
    assertThat("Incorrect parameter value", rq.getParameters().get(0).getValue(), is("param_0"));
    assertThat("Incorrect parameter key", rq.getParameters().get(1).getKey(), is("message_1"));
    assertThat("Incorrect parameter value", rq.getParameters().get(1).getValue(), is("param_1"));
}
Also used : Method(java.lang.reflect.Method) ITestNGMethod(org.testng.ITestNGMethod) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Aggregations

StartTestItemRQ (com.epam.ta.reportportal.ws.model.StartTestItemRQ)159 Test (org.junit.jupiter.api.Test)124 FinishTestItemRQ (com.epam.ta.reportportal.ws.model.FinishTestItemRQ)30 List (java.util.List)21 TestNG (org.testng.TestNG)21 Launch (com.epam.reportportal.service.Launch)20 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 TestNgListener (com.epam.reportportal.testng.util.TestNgListener)18 Collectors (java.util.stream.Collectors)17 ArgumentCaptor (org.mockito.ArgumentCaptor)17 ReportPortal (com.epam.reportportal.service.ReportPortal)16 ReportPortalClient (com.epam.reportportal.service.ReportPortalClient)15 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)15 ArgumentMatchers.same (org.mockito.ArgumentMatchers.same)14 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)13 ItemAttributesRQ (com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)13 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)12 Set (java.util.Set)12 Nonnull (javax.annotation.Nonnull)12