@Override public void accept(Propagation<?> propagation) { TraceContext.Injector<Map<Object, String>> injector = propagation.injector(Map::put); TraceContext.Extractor<Map<Object, String>> extractor = propagation.extractor(Map::get); TraceContext ctx = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false).build(); Map<Object, String> map = new LinkedHashMap<>(); injector.inject(ctx, map); assertThat(extractor.extract(map).context()) .isEqualToIgnoringGivenFields(ctx, "traceIdString", "spanIdString"); } }
@Override public void accept(Propagation<?> propagation) { TraceContext.Injector<Map<Object, String>> injector = propagation.injector(Map::put); TraceContext.Extractor<Map<Object, String>> extractor = propagation.extractor(Map::get); TraceContext ctx = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false).build(); Map<Object, String> map = new LinkedHashMap<>(); injector.inject(ctx, map); assertThat(extractor.extract(map).context()) .isEqualToIgnoringGivenFields(ctx, "traceIdString", "spanIdString"); } }
@Test public void testUpdateByUsername() { String series = "someSeries"; PersistentRememberMeToken rememberMeToken = new PersistentRememberMeToken("abdullah", series, "oldToken", new Date()); sessionTokenRepository.createNewToken(rememberMeToken); sessionTokenRepository.updateToken("abdullah", "farida"); PersistentRememberMeToken tokenFromDb = sessionTokenRepository.getTokenForSeries(series); assertThat(tokenFromDb.getUsername()).isEqualTo("farida"); assertThat(tokenFromDb).isEqualToIgnoringGivenFields(rememberMeToken, "username"); }
@Test public void testSave_DoMappingUsingDozerAndThenSavesDocumentIntoMongodb() { inventoryMongoRepository.save(new Inventory("Apple Watch", 20.0)); List<InventoryDocument> allInventory = mongoOperations.findAll(InventoryDocument.class); assertThat(allInventory).hasSize(1); assertThat(allInventory.get(0).getId()).isNotNull(); assertThat(allInventory.get(0)) .isEqualToIgnoringGivenFields(new InventoryDocument("Apple Watch", 20.0), "id"); }
@Test public void shouldCreateIntegrations() { 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(); final Integration created = new Integration.Builder().build(); final Integration encrypted = new Integration.Builder().addTag("encrypted").build(); when(encryptionSupport.encrypt(integration)).thenReturn(encrypted); final ArgumentCaptor<Integration> persisted = ArgumentCaptor.forClass(Integration.class); when(dataManager.create(persisted.capture())).thenReturn(created); assertThat(handler.create(security, integration)).isSameAs(created); assertThat(persisted.getValue()).isEqualToIgnoringGivenFields(encrypted, "createdAt"); verify(encryptionSupport).encrypt(same(integration)); }
@Test public void testGetAndDeleteOldestEvent() { restEventMongoRepository.save(createEvent("r1", "pr1", "po1", "opr1", LocalDate.now())); restEventMongoRepository.save(createEvent("r2", "pr2", "po2", "opr2", LocalDate.now().minusDays(1))); restEventMongoRepository.save(createEvent("r3", "pr3", "po3", "opr3", LocalDate.now().minusDays(2))); RestEvent oldest = createEvent("r4", "pr4", "po4", "opr4", LocalDate.now().minusDays(3)); restEventMongoRepository.save(oldest); RestEvent oldestEventFromMongo = restEventMongoRepository.getOldestEvent(); assertThat(oldestEventFromMongo).isEqualToIgnoringGivenFields(oldest, "id"); RestEvent deleteOldestEvent = restEventMongoRepository.deleteOldestEvent(); assertThat(deleteOldestEvent).isEqualToIgnoringGivenFields(oldest, "id"); assertThat(restEventMongoRepository.count()).isEqualTo(3); }
@Test public void testGetAndDeleteOldestEvent() { soapEventMongoRepository.save(createEvent("r1", "pr1", "po1", "opr1", LocalDate.now())); soapEventMongoRepository.save(createEvent("r2", "pr2", "po2", "opr2", LocalDate.now().minusDays(1))); soapEventMongoRepository.save(createEvent("r3", "pr3", "po3", "opr3", LocalDate.now().minusDays(2))); SoapEvent oldest = createEvent("r4", "pr4", "po4", "opr4", LocalDate.now().minusDays(3)); soapEventMongoRepository.save(oldest); SoapEvent oldestEventFromMongo = soapEventMongoRepository.getOldestEvent(); assertThat(oldestEventFromMongo).isEqualToIgnoringGivenFields(oldest, "id"); SoapEvent deleteOldestEvent = soapEventMongoRepository.deleteOldestEvent(); assertThat(deleteOldestEvent).isEqualToIgnoringGivenFields(oldest, "id"); assertThat(soapEventMongoRepository.count()).isEqualTo(3); }
@Test public void createShouldCreateWithUnspecifiedIds() { final Connector given = new Connector.Builder().icon("my-icon").build(); final Connector got = dataManager.create(given); assertThat(got).isEqualToIgnoringGivenFields(given, "id"); assertThat(got.getId()).isPresent(); assertThat(cacheManager.getCache(Kind.Connector.modelName).get(got.getId().get())).isSameAs(got); }
@Test public void shouldDoBasicOperations() throws Exception { final FileBasedSessionManager manager = new FileBasedSessionManager(rootDir.newFolder().toPath(), "0 0 0 ? * * 2099"); final Session session = new Session(manager.generateSessionId(), "username", Duration.ofHours(1)); manager.create(session).join(); assertThat(manager.get(session.id()).join()) .isEqualToIgnoringGivenFields(session, "rawSession"); final Session updatedSession = new Session(session.id(), "username2", Duration.ofHours(2)); manager.update(updatedSession).join(); assertThat(manager.get(updatedSession.id()).join()) .isEqualToIgnoringGivenFields(updatedSession, "rawSession"); manager.delete(updatedSession.id()).join(); assertThat(manager.get(updatedSession.id()).join()).isNull(); }
@Test public void testFindRestResourceByUri() { RestResource toMatch = createRestResource("app1", "uri1"); restResourceMongoRepository.save(toMatch); restResourceMongoRepository.save(createRestResource("app1", "xxURI12")); RestResource fromDb = restResourceMongoRepository.findRestResourceByUri("app1", "URI1"); assertThat(fromDb).isEqualToIgnoringGivenFields(toMatch, "id"); }
@Test public void shouldDeserializeFromJson() throws IOException { final String json = "{\"type\":\"OAUTH1\",\"accessToken\":{\"value\":\"access-token-value\",\"secret\":\"access-token-secret\"},\"token\":{\"value\":\"token-value\",\"secret\":\"token-secret\"},\"verifier\":\"verifier\",\"key\":\"key\",\"providerId\":\"twitter\",\"returnUrl\":\"https://localhost:4200/connections/create/configure-fields?state=create-connection&connectorId=twitter\"}"; final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new CredentialModule()); final OAuth1CredentialFlowState flowState = mapper.readerFor(CredentialFlowState.class).readValue(json); final OAuth1CredentialFlowState expected = new OAuth1CredentialFlowState.Builder() .accessToken(new OAuthToken("access-token-value", "access-token-secret")) .token(new OAuthToken("token-value", "token-secret")).verifier("verifier").key("key").providerId("twitter") .returnUrl(URI.create( "https://localhost:4200/connections/create/configure-fields?state=create-connection&connectorId=twitter")) .build(); assertThat(flowState).isEqualToIgnoringGivenFields(expected, "accessToken", "token"); assertThat(flowState.getAccessToken()).isEqualToComparingFieldByField(expected.getAccessToken()); assertThat(flowState.getToken()).isEqualToComparingFieldByField(expected.getToken()); }
@Test public void shouldProvideInfoFromPetstoreSwagger() throws IOException { final String specification = resource("/swagger/petstore.swagger.json"); final ConnectorSettings connectorSettings = new ConnectorSettings.Builder()// .putConfiguredProperty("specification", specification)// .build(); final APISummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings); final ActionsSummary actionsSummary = new ActionsSummary.Builder().totalActions(20).putActionCountByTag("store", 4) .putActionCountByTag("user", 8).putActionCountByTag("pet", 8).build(); final APISummary expected = new APISummary.Builder()// .name("Swagger Petstore")// .actionsSummary(actionsSummary)// .build(); assertThat(summary).isEqualToIgnoringGivenFields(expected, "icon", "description", "properties", "warnings", "configuredProperties"); assertThat(summary.getIcon()).matches(s -> s.isPresent() && s.get().startsWith("data:image")); assertThat(summary.getDescription()).startsWith("This is a sample server Petstore server"); assertThat(summary.getProperties().keySet()).contains("host", "basePath", "authenticationType", "clientId", "clientSecret", "accessToken", "authorizationEndpoint", "oauthScopes", "specification"); assertThat(summary.getConfiguredProperties().keySet()).containsOnly("specification"); assertThat(reformatJson(summary.getConfiguredProperties().get("specification"))).isEqualTo(reformatJson(specification)); }
@Test public void shouldProvideInfoFromPetstoreSwagger() throws IOException { final String specification = resource("/swagger/petstore.swagger.json"); final ConnectorSettings connectorSettings = new ConnectorSettings.Builder()// .putConfiguredProperty("specification", specification)// .build(); final ConnectorSummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings); final ActionsSummary actionsSummary = new ActionsSummary.Builder().totalActions(20).putActionCountByTag("store", 4) .putActionCountByTag("user", 8).putActionCountByTag("pet", 8).build(); final ConnectorSummary expected = new ConnectorSummary.Builder()// .name("Swagger Petstore")// .actionsSummary(actionsSummary)// .build(); assertThat(summary).isEqualToIgnoringGivenFields(expected, "icon", "description", "properties", "warnings", "configuredProperties"); assertThat(summary.getIcon()).startsWith("data:image"); assertThat(summary.getDescription()).startsWith("This is a sample server Petstore server"); assertThat(summary.getProperties().keySet()).contains("host", "basePath", "authenticationType", "clientId", "clientSecret", "accessToken", "authorizationEndpoint", "oauthScopes", "specification"); assertThat(summary.getConfiguredProperties().keySet()).containsOnly("specification"); assertThat(reformatJson(summary.getConfiguredProperties().get("specification"))).isEqualTo(reformatJson(specification)); }
@Test public void shouldCreateBaseConnectors() { final ConnectorSettings settings = new ConnectorSettings.Builder().putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields(// new Connector.Builder()// .name("test-name")// .description("test-description")// .connectorGroup(template.getConnectorGroup())// .connectorGroupId("template-group")// .properties(template.getConnectorProperties())// .putConfiguredProperty("property2", "value2")// .build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); }
@Test public void shouldCreateBaseConnectors() { final ConnectorSettings settings = new ConnectorSettings.Builder().putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields(// new Connector.Builder()// .name("test-name")// .description("test-description")// .connectorGroup(template.getConnectorGroup())// .connectorGroupId("template-group")// .properties(template.getConnectorProperties())// .putConfiguredProperty("property2", "value2")// .build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); }
@Test public void shouldCreateBaseConnectors() { final ConnectorSettings settings = new ConnectorSettings.Builder().putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields(// new Connector.Builder()// .name("test-name")// .description("test-description")// .connectorGroup(template.getConnectorGroup())// .connectorGroupId("template-group")// .properties(template.getConnectorProperties())// .putConfiguredProperty("property2", "value2")// .build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); }
@Test public void shouldProvideInfoFromPetstoreSwagger() throws IOException { final String specification = resource("/swagger/petstore.swagger.json"); final ConnectorSettings connectorSettings = new ConnectorSettings.Builder()// .putConfiguredProperty("specification", specification)// .build(); final ConnectorSummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings); final ActionsSummary actionsSummary = new ActionsSummary.Builder().totalActions(20).putActionCountByTag("store", 4) .putActionCountByTag("user", 8).putActionCountByTag("pet", 8).build(); final ConnectorSummary expected = new ConnectorSummary.Builder()// .name("Swagger Petstore")// .actionsSummary(actionsSummary)// .build(); assertThat(summary).isEqualToIgnoringGivenFields(expected, "icon", "description", "properties", "warnings"); assertThat(summary.getIcon()).startsWith("data:image"); assertThat(summary.getDescription()).startsWith("This is a sample server Petstore server"); assertThat(summary.getProperties().keySet()).contains("host", "basePath", "authenticationType", "clientId", "clientSecret", "accessToken", "authorizationEndpoint", "specification"); }
@Test public void shouldCreateBaseConnectorsWithGivenNameAndDescription() { final ConnectorSettings settings = new ConnectorSettings.Builder().name("given-name").description("given-description") .putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields(// new Connector.Builder()// .name("given-name")// .description("given-description")// .connectorGroup(template.getConnectorGroup())// .connectorGroupId("template-group")// .properties(template.getConnectorProperties())// .putConfiguredProperty("property2", "value2").build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); } }
@Test public void shouldCreateBaseConnectorsWithGivenNameAndDescription() { final ConnectorSettings settings = new ConnectorSettings.Builder().name("given-name").description("given-description") .putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields(// new Connector.Builder()// .name("given-name")// .description("given-description")// .connectorGroup(template.getConnectorGroup())// .connectorGroupId("template-group")// .properties(template.getConnectorProperties())// .putConfiguredProperty("property2", "value2").build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); } }
@Test public void shouldCreateBaseConnectorsWithGivenNameAndDescription() { final ConnectorSettings settings = new ConnectorSettings.Builder().name("given-name").description("given-description") .putConfiguredProperty("property2", "value2").build(); final Connector connector = generator.baseConnectorFrom(template, settings); assertThat(connector).isEqualToIgnoringGivenFields(// new Connector.Builder()// .name("given-name")// .description("given-description")// .connectorGroup(template.getConnectorGroup())// .connectorGroupId("template-group")// .properties(template.getConnectorProperties())// .putConfiguredProperty("property2", "value2").build(), "id", "icon"); assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy"); } }