Search in sources :

Example 1 with CustomAttribute

use of org.testng.annotations.CustomAttribute in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testRecordResultTestInError.

@Test(groups = { "ut" })
public void testRecordResultTestInError(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(false);
    when(testResult.getStatus()).thenReturn(2);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenReturn(campaign);
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we call all necessary API methods to record the result
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api).addTestCaseInIteration(iteration, 1);
    verify(api).setExecutionResult(iterationTestPlanItem, ExecutionStatus.FAILURE);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Example 2 with CustomAttribute

use of org.testng.annotations.CustomAttribute in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testRecordResultTestWrongTestId.

/**
 * Check that if the testID is not valid, we raise an error
 * @param testContext
 */
@Test(groups = { "ut" })
public void testRecordResultTestWrongTestId(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(true);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenReturn(campaign);
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we call all necessary API methods to record the result
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api).addTestCaseInIteration(iteration, 1);
    verify(api).setExecutionResult(iterationTestPlanItem, ExecutionStatus.SUCCESS);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Example 3 with CustomAttribute

use of org.testng.annotations.CustomAttribute in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testRecordResultTestInSuccess.

@Test(groups = { "ut" })
public void testRecordResultTestInSuccess(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(true);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenReturn(campaign);
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we call all necessary API methods to record the result
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api).addTestCaseInIteration(iteration, 1);
    verify(api).setExecutionResult(iterationTestPlanItem, ExecutionStatus.SUCCESS);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Example 4 with CustomAttribute

use of org.testng.annotations.CustomAttribute in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testRecordResultTestSkipped.

@Test(groups = { "ut" })
public void testRecordResultTestSkipped(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(false);
    when(testResult.getStatus()).thenReturn(3);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenReturn(campaign);
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we call all necessary API methods to record the result
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api).addTestCaseInIteration(iteration, 1);
    verify(api).setExecutionResult(iterationTestPlanItem, ExecutionStatus.BLOCKED);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Example 5 with CustomAttribute

use of org.testng.annotations.CustomAttribute in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testNoExceptionWhenErrorInRecording.

/**
 * Check that if any error occurs during result recording, it does not raise any exception, only message will be displayed
 * @param testContext
 */
@Test(groups = { "ut" })
public void testNoExceptionWhenErrorInRecording(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(true);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenThrow(new ScenarioException("Something went wrong"));
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we do not call API as testId is not provided
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api, never()).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api, never()).addTestCaseInIteration(iteration, 1);
    verify(api, never()).setExecutionResult(iterationTestPlanItem, ExecutionStatus.SUCCESS);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) ScenarioException(com.seleniumtests.customexception.ScenarioException) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

MockitoTest (com.seleniumtests.MockitoTest)5 SquashTMConnector (com.seleniumtests.connectors.tms.squash.SquashTMConnector)5 Campaign (com.seleniumtests.connectors.tms.squash.entities.Campaign)5 JSONObject (org.json.JSONObject)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CustomAttribute (org.testng.annotations.CustomAttribute)5 Test (org.testng.annotations.Test)5 ScenarioException (com.seleniumtests.customexception.ScenarioException)1