@Test public void shouldFetchIntegrationDeployments() { final IntegrationDeployment expected = deployment(0); when(dataManager.fetch(IntegrationDeployment.class, compositeId(INTEGRATION_ID, 3))).thenReturn(expected); final IntegrationDeployment got = handler.get(INTEGRATION_ID, 3); assertThat(got).isEqualTo(expected); }
@Test public void shouldSetVersionTo1ForInitialUpdate() { final SecurityContext security = mock(SecurityContext.class); final Principal principal = mock(Principal.class); when(security.getUserPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("user"); final Integration integration = new Integration.Builder().build(); when(dataManager.fetch(Integration.class, INTEGRATION_ID)).thenReturn(integration); when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", INTEGRATION_ID)) .thenReturn(Stream.empty()); handler.update(security, INTEGRATION_ID); final IntegrationDeployment expected = new IntegrationDeployment.Builder().id(compositeId(INTEGRATION_ID, 1)) .spec(integration).version(1).userId("user").build(); verify(dataManager).create(expected); }
@Test public void shouldUpdateIntegrationDeploymentTargetState() { final TargetStateRequest targetState = new TargetStateRequest(); targetState.targetState = IntegrationDeploymentState.Published; final IntegrationDeployment existing = deployment(0); when(dataManager.fetch(IntegrationDeployment.class, compositeId(INTEGRATION_ID, 3))).thenReturn(existing); handler.updateTargetState(INTEGRATION_ID, 3, targetState); final IntegrationDeployment expected = new IntegrationDeployment.Builder().createFrom(existing) .targetState(IntegrationDeploymentState.Published).build(); verify(dataManager).update(expected); }
final String compositeId = IntegrationDeployment.compositeId(integrationId, integrationDeployment.getVersion()); final IntegrationDeploymentState targetState = integrationDeployment.getTargetState();
@Test public void shouldUpdateIntegrationDeployments() { final SecurityContext security = mock(SecurityContext.class); final Principal principal = mock(Principal.class); when(security.getUserPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("user"); final Integration integration = new Integration.Builder().build(); when(dataManager.fetch(Integration.class, INTEGRATION_ID)).thenReturn(integration); final IntegrationDeployment deployment1 = new IntegrationDeployment.Builder().createFrom(deployment(0)) .targetState(IntegrationDeploymentState.Unpublished).build(); final IntegrationDeployment deployment2 = deployment(1); final IntegrationDeployment deployment3 = deployment(2); when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", INTEGRATION_ID)) .thenReturn(Stream.of(deployment1, deployment2, deployment3)); handler.update(security, INTEGRATION_ID); final IntegrationDeployment expected = new IntegrationDeployment.Builder().id(compositeId(INTEGRATION_ID, 3)) .spec(integration).version(3).userId("user").build(); verify(dataManager).update(unpublished(1)); verify(dataManager).update(unpublished(2)); verify(dataManager).create(expected); }