use of io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData in project syndesis by syndesisio.
the class IntegrationSpecificationHandlerTest method shouldStoreUpdatedSpecificationForNonFlowChanges.
@Test
public void shouldStoreUpdatedSpecificationForNonFlowChanges() {
final Step step = new Step.Builder().action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().build()).build()).build();
final Integration integration = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").addSteps(step, step).build()).build();
final byte[] updatedSpecificationDocument = "updated specification".getBytes(StandardCharsets.UTF_8);
final OpenApi updatedSpecification = new OpenApi.Builder().document(updatedSpecificationDocument).build();
final APIIntegration updatedApiIntegration = new APIIntegration(integration, updatedSpecification);
when(dataManager.fetch(Connection.class, "api-provider")).thenReturn(new Connection.Builder().connectorId("api-provider-connector").build());
when(dataManager.fetch(Connector.class, "api-provider-connector")).thenReturn(new Connector.Builder().build());
when(dataManager.fetch(Integration.class, "integration-1")).thenReturn(integration);
when(encryptionSupport.encrypt(integration)).thenReturn(integration);
when(apiGenerator.generateIntegration(any(String.class), any(ProvidedApiTemplate.class))).thenReturn(updatedApiIntegration);
when(apiGenerator.updateFlowExcerpts(any(Integration.class))).then(ctx -> ctx.getArguments()[0]);
final APIFormData openApiUpdate = new APIFormData();
openApiUpdate.setSpecification(new ByteArrayInputStream(updatedSpecificationDocument));
handler.update("integration-1", openApiUpdate);
verify(dataManager).store(updatedSpecification, OpenApi.class);
verify(dataManager).update(ArgumentMatchers.<Integration>argThat(v -> {
assertThat(v).isEqualToIgnoringGivenFields(integration, "version", "updatedAt");
assertThat(v.getVersion()).isEqualTo(2);
return true;
}));
}
use of io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData in project syndesis by syndesisio.
the class IntegrationSpecificationHandlerTest method shouldPerformUpdatesBasedOnNewSpecification.
@Test
public void shouldPerformUpdatesBasedOnNewSpecification() {
final Integration existing = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").build()).build();
final Integration given = new Integration.Builder().id("integration-2").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow2").build()).build();
final Integration expected = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow2").build()).build();
final OpenApi updatedSpecification = new OpenApi.Builder().build();
final APIIntegration updatedApiIntegration = new APIIntegration(given, updatedSpecification);
when(dataManager.fetch(Connection.class, "api-provider")).thenReturn(new Connection.Builder().connectorId("api-provider-connector").build());
when(dataManager.fetch(Connector.class, "api-provider-connector")).thenReturn(new Connector.Builder().build());
when(dataManager.fetch(Integration.class, "integration-1")).thenReturn(existing);
when(encryptionSupport.encrypt(expected)).thenReturn(expected);
when(apiGenerator.generateIntegration(any(String.class), any(ProvidedApiTemplate.class))).thenReturn(updatedApiIntegration);
when(apiGenerator.updateFlowExcerpts(any(Integration.class))).then(ctx -> ctx.getArguments()[0]);
final APIFormData openApiUpdate = new APIFormData();
openApiUpdate.setSpecification(new ByteArrayInputStream("updated specification".getBytes(StandardCharsets.UTF_8)));
handler.update("integration-1", openApiUpdate);
verify(dataManager).store(updatedSpecification, OpenApi.class);
verify(dataManager).update(ArgumentMatchers.<Integration>argThat(v -> {
assertThat(v).isEqualToIgnoringGivenFields(expected, "version", "updatedAt");
assertThat(v.getVersion()).isEqualTo(2);
return true;
}));
}
Aggregations