Search in sources :

Example 16 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class GlobalSchedulingConfigActionsTest method validateConfigWithValidArgsTest.

@Test
public void validateConfigWithValidArgsTest() {
    final GlobalSchedulingConfigActions configActions = new GlobalSchedulingConfigActions(null, null, null, null, new ObjectTransformer(), null, null, null);
    final GlobalSchedulingConfigRestModel restModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    String validationString = null;
    AlertFieldException caughtException = null;
    try {
        validationString = configActions.validateConfig(restModel);
    } catch (final AlertFieldException e) {
        caughtException = e;
    }
    assertNull(caughtException);
    assertEquals("Valid", validationString);
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 17 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class GlobalSchedulingConfigActionsTest method testInvalidConfig.

@Test
@Override
public void testInvalidConfig() {
    final String invalidCron = "invalid";
    final GlobalSchedulingConfigActions configActions = new GlobalSchedulingConfigActions(null, null, null, null, new ObjectTransformer(), null, null, null);
    GlobalSchedulingConfigRestModel restModel = new GlobalSchedulingConfigRestModel("1", invalidCron, invalidCron, invalidCron, invalidCron, invalidCron);
    AlertFieldException caughtException = null;
    try {
        configActions.validateConfig(restModel);
    } catch (final AlertFieldException e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    assertEquals("Must be a number between 0 and 23", caughtException.getFieldErrors().get("dailyDigestHourOfDay"));
    assertEquals("Must be a number between 1 and 7", caughtException.getFieldErrors().get("purgeDataFrequencyDays"));
    assertEquals(2, caughtException.getFieldErrors().size());
    restModel = new GlobalSchedulingConfigRestModel("1", "-1", "-1", "-1", "-1", "-1");
    caughtException = null;
    try {
        configActions.validateConfig(restModel);
    } catch (final AlertFieldException e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    assertEquals("Must be a number between 0 and 23", caughtException.getFieldErrors().get("dailyDigestHourOfDay"));
    assertEquals("Must be a number between 1 and 7", caughtException.getFieldErrors().get("purgeDataFrequencyDays"));
    assertEquals(2, caughtException.getFieldErrors().size());
    restModel = new GlobalSchedulingConfigRestModel("1", "100000", "100000", "100000", "100000", "100000");
    caughtException = null;
    try {
        configActions.validateConfig(restModel);
    } catch (final AlertFieldException e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    assertEquals("Must be a number less than 24", caughtException.getFieldErrors().get("dailyDigestHourOfDay"));
    assertEquals("Must be a number less than 8", caughtException.getFieldErrors().get("purgeDataFrequencyDays"));
    assertEquals(2, caughtException.getFieldErrors().size());
    restModel = new GlobalSchedulingConfigRestModel("1", "", "", "", "", "");
    caughtException = null;
    try {
        configActions.validateConfig(restModel);
    } catch (final AlertFieldException e) {
        caughtException = e;
    }
    assertNotNull(caughtException);
    assertEquals("Must be a number between 0 and 23", caughtException.getFieldErrors().get("dailyDigestHourOfDay"));
    assertEquals("Must be a number between 1 and 7", caughtException.getFieldErrors().get("purgeDataFrequencyDays"));
    assertEquals(2, caughtException.getFieldErrors().size());
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 18 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class ControllerHandlerTest method testCreateResponse.

@Test
public void testCreateResponse() {
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final ControllerHandlerTestObject controllerHandlerTestObject = new ControllerHandlerTestObject(objectTransformer);
    final ResponseEntity<String> responseEntity = controllerHandlerTestObject.createResponse(HttpStatus.CHECKPOINT, "Test");
    assertEquals(HttpStatus.CHECKPOINT, responseEntity.getStatusCode());
    assertEquals("{\"id\":-1,\"message\":\"Test\"}", responseEntity.getBody());
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Test(org.junit.Test)

Example 19 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class ControllerHandlerTest method testCreateResponseWithStringID.

@Test
public void testCreateResponseWithStringID() {
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final ControllerHandlerTestObject controllerHandlerTestObject = new ControllerHandlerTestObject(objectTransformer);
    final ResponseEntity<String> responseEntity = controllerHandlerTestObject.createResponse(HttpStatus.CHECKPOINT, "11", "Test");
    assertEquals(HttpStatus.CHECKPOINT, responseEntity.getStatusCode());
    assertEquals("{\"id\":11,\"message\":\"Test\"}", responseEntity.getBody());
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Test(org.junit.Test)

Example 20 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class ControllerHandlerTest method testCreateResponseWithLongID.

@Test
public void testCreateResponseWithLongID() {
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final ControllerHandlerTestObject controllerHandlerTestObject = new ControllerHandlerTestObject(objectTransformer);
    final ResponseEntity<String> responseEntity = controllerHandlerTestObject.createResponse(HttpStatus.CHECKPOINT, 21L, "Test");
    assertEquals(HttpStatus.CHECKPOINT, responseEntity.getStatusCode());
    assertEquals("{\"id\":21,\"message\":\"Test\"}", responseEntity.getBody());
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Test(org.junit.Test)

Aggregations

ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)26 Test (org.junit.Test)19 Gson (com.google.gson.Gson)8 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)5 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)4 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)4 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)4 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 GlobalEmailRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper)2 GlobalHipChatRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatRepositoryWrapper)2 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)2 NotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper)2 VulnerabilityRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)2 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)2 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2