@Test public void importSelectorsWithNestedGroupSameDeferredImport() { DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); context.register(ParentConfiguration2.class); context.refresh(); InOrder ordered = inOrder(beanFactory); ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any()); assertThat(TestImportGroup.instancesCount.get(), equalTo(2)); assertThat(TestImportGroup.allImports().size(), equalTo(2)); assertThat(TestImportGroup.allImports(), hasEntry( is(ParentConfiguration2.class.getName()), IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName(), ChildConfiguration2.class.getName()))); assertThat(TestImportGroup.allImports(), hasEntry( is(ChildConfiguration2.class.getName()), IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName()))); }
@Test public void importSelectorsWithNestedGroup() { DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory()); AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory); context.register(ParentConfiguration1.class); context.refresh(); InOrder ordered = inOrder(beanFactory); ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("e"), any()); ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any()); assertThat(TestImportGroup.instancesCount.get(), equalTo(2)); assertThat(TestImportGroup.imports.size(), equalTo(2)); assertThat(TestImportGroup.allImports(), hasEntry( is(ParentConfiguration1.class.getName()), IsIterableContainingInOrder.contains(DeferredImportSelector1.class.getName(), ChildConfiguration1.class.getName()))); assertThat(TestImportGroup.allImports(), hasEntry( is(ChildConfiguration1.class.getName()), IsIterableContainingInOrder.contains(DeferredImportedSelector3.class.getName()))); }
private void checkAdded(final Map<String, String> addedMap) { assertThat("unwanted entry change", addedMap, hasEntry("test1", "one")); assertThat("existing entry not updated", addedMap, hasEntry("test2", "2")); assertThat("new entry not added", addedMap, hasEntry("test3", "three")); assertThat("wrong size", addedMap, hasSize(3)); }
@Test public void shouldCreateSetHeaderFields() { final HttpRequest httpRequest = httpGetRequest(URL) .headerField("HEADER1", "VALUE1") .headerField("HEADER2", "VALUE2") .compile(); final Map<String, String> header = httpRequest.header; assertThat(header, hasEntry("HEADER1", "VALUE1")); assertThat(header, hasEntry("HEADER2", "VALUE2")); }
@Test public void publishArtifactResponse_shouldDeserializeFromJson() { final ArtifactMessageConverterV1 converter = new ArtifactMessageConverterV1(); final PublishArtifactResponse response = converter.publishArtifactResponse("{\n" + " \"metadata\": {\n" + " \"artifact-version\": \"10.12.0\"\n" + " }\n" + "}"); MatcherAssert.assertThat(response.getMetadata().size(), is(1)); MatcherAssert.assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0")); }
@Test public void canReadMapWithTwoValues() throws Exception { Map<String, Object> map = input.readMap( "{\"key1\":\"value1\", \"key2\":\"value11\"}" ); assertNotNull( map ); assertThat( map, hasEntry( "key1", "value1" ) ); assertThat( map, hasEntry( "key2", "value11" ) ); assertEquals( "map contained extra values", 2, map.size() ); }
@Test public void canReadMapWithTwoValues() throws Exception { Map<String, Object> map = input.readMap( "{\"key1\":\"value1\", \"key2\":\"value11\"}" ); assertNotNull( map ); assertThat( map, hasEntry( "key1", "value1" ) ); assertThat( map, hasEntry( "key2", "value11" ) ); assertEquals( "map contained extra values", 2, map.size() ); }
@Test public void shouldAbleToSetRequestHeaders() throws Exception { final DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest("extension", "1.0", "request-name"); final Map<String, String> headers = new HashMap(); headers.put("HEADER-1", "HEADER-VALUE-1"); headers.put("HEADER-2", "HEADER-VALUE-2"); request.setRequestHeaders(headers); assertThat(request.requestHeaders(), hasEntry("HEADER-1", "HEADER-VALUE-1")); assertThat(request.requestHeaders(), hasEntry("HEADER-2", "HEADER-VALUE-2")); } }
@Test public void shouldAddMetadataWhenMetadataOfOtherArtifactIsAlreadyPresetForAPlugin() { final PluggableArtifactMetadata pluggableArtifactMetadata = new PluggableArtifactMetadata(); assertTrue(pluggableArtifactMetadata.getMetadataPerPlugin().isEmpty()); pluggableArtifactMetadata.addMetadata("docker", "centos", Collections.singletonMap("image", "centos")); pluggableArtifactMetadata.addMetadata("docker", "alpine", Collections.singletonMap("image", "alpine")); final Map<String, Map> docker = pluggableArtifactMetadata.getMetadataPerPlugin().get("docker"); assertNotNull(docker); assertThat(docker, Matchers.hasEntry("centos", Collections.singletonMap("image", "centos"))); assertThat(docker, Matchers.hasEntry("alpine", Collections.singletonMap("image", "alpine"))); }
@Test public void sessionAttributePredicate() { MockWebSession session = new MockWebSession(); session.getAttributes().put("a1", "v1"); session.getAttributes().put("a2", "v2"); session.getAttributes().put("a3", "v3"); session.getAttributes().put("a4", "v4"); session.getAttributes().put("a5", "v5"); MockServerHttpRequest request = initHandshakeRequest(); MockServerWebExchange exchange = MockServerWebExchange.builder(request).session(session).build(); TestRequestUpgradeStrategy upgradeStrategy = new TestRequestUpgradeStrategy(); HandshakeWebSocketService service = new HandshakeWebSocketService(upgradeStrategy); service.setSessionAttributePredicate(name -> Arrays.asList("a1", "a3", "a5").contains(name)); service.handleRequest(exchange, mock(WebSocketHandler.class)).block(); HandshakeInfo info = upgradeStrategy.handshakeInfo; assertNotNull(info); Map<String, Object> attributes = info.getAttributes(); assertEquals(3, attributes.size()); assertThat(attributes, Matchers.hasEntry("a1", "v1")); assertThat(attributes, Matchers.hasEntry("a3", "v3")); assertThat(attributes, Matchers.hasEntry("a5", "v5")); }
@Test public void shouldAddMetadataWhenMetadataAbsentForPlugin() { final PluggableArtifactMetadata pluggableArtifactMetadata = new PluggableArtifactMetadata(); assertTrue(pluggableArtifactMetadata.getMetadataPerPlugin().isEmpty()); pluggableArtifactMetadata.addMetadata("docker", "installer", Collections.singletonMap("image", "alpine")); assertThat(pluggableArtifactMetadata.getMetadataPerPlugin(), Matchers.hasEntry("docker", Collections.singletonMap("installer", Collections.singletonMap("image", "alpine")))); }
@Test public void shouldConvertPluggableArtifactConfigToArtifactPlans() { final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("ID", "StoreID", create("Foo", true, "Bar"), create("Baz", false, "Car")); final ArtifactPlan artifactPlan = new ArtifactPlan(artifactConfig); assertThat(artifactPlan.getArtifactPlanType(), is(ArtifactPlanType.external)); assertThat(artifactPlan.getPluggableArtifactConfiguration().size(), is(3)); assertThat(artifactPlan.getPluggableArtifactConfiguration(), hasEntry("id", "ID")); assertThat(artifactPlan.getPluggableArtifactConfiguration(), hasEntry("storeId", "StoreID")); final Map<String, String> configuration = (Map<String, String>) artifactPlan.getPluggableArtifactConfiguration().get("configuration"); assertThat(configuration.size(), is(2)); assertThat(configuration, hasEntry("Foo", "Bar")); assertThat(configuration, hasEntry("Baz", "Car")); } }
@Test public void shouldBeUniqueBasedOnpipelineAndStageName() throws Exception { DependencyMaterial material1 = new DependencyMaterial(new CaseInsensitiveString("pipeline1"), new CaseInsensitiveString("stage1")); Map<String, Object> map = new HashMap<>(); material1.appendCriteria(map); assertThat(map, hasEntry("pipelineName", "pipeline1")); assertThat(map, hasEntry("stageName", "stage1")); assertThat(map.size(), is(2)); }
@Test public void shouldRespondWithMetadataToDiscardAll() throws Throwable { // When negotiateBoltV3(); connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), DiscardAllMessage.INSTANCE ) ); // Then Matcher<Map<? extends String,?>> entryTypeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); Matcher<Map<? extends String,?>> entryFieldsMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldsMatcher, hasKey( "t_first" ) ) ), msgSuccess( allOf( entryTypeMatcher, hasKey( "t_last" ), hasKey( "bookmark" ) ) ) ) ); }
@Test public void canReadMapWithNestedMap() throws Exception { Map<String, Object> map = input.readMap( "{\"nested\": {\"key\": \"valuable\"}}" ); assertNotNull( map ); assertThat( map, hasKey( "nested" ) ); assertEquals( "map contained extra values", 1, map.size() ); Object nested = map.get( "nested" ); assertThat( nested, instanceOf( Map.class ) ); @SuppressWarnings( "unchecked" ) Map<String, String> nestedMap = (Map<String, String>) nested; assertThat( nestedMap, hasEntry( "key", "valuable" ) ); }
@Test public void canReadMapWithNestedMap() throws Exception { Map<String, Object> map = input.readMap( "{\"nested\": {\"key\": \"valuable\"}}" ); assertNotNull( map ); assertThat( map, hasKey( "nested" ) ); assertEquals( "map contained extra values", 1, map.size() ); Object nested = map.get( "nested" ); assertThat( nested, instanceOf( Map.class ) ); @SuppressWarnings( "unchecked" ) Map<String, String> nestedMap = (Map<String, String>) nested; assertThat( nestedMap, hasEntry( "key", "valuable" ) ); }
@Test public void shouldCloseConnectionInStreaming() throws Throwable { // Given negotiateBoltV3(); // When connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ) ); Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ) ) ); // you shall be in the streaming state now connection.send( util.chunk( GOODBYE_MESSAGE ) ); // Then assertThat( connection, serverImmediatelyDisconnects() ); assertThat( server, eventuallyClosesTransaction() ); }
@Test public void shouldCloseConnectionInTxStreaming() throws Throwable { // Given negotiateBoltV3(); // When connection.send( util.chunk( new BeginMessage(), new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ) ); Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ) ) ); // you shall be in the tx_streaming state now connection.send( util.chunk( GOODBYE_MESSAGE ) ); // Then assertThat( connection, serverImmediatelyDisconnects() ); assertThat( server, eventuallyClosesTransaction() ); }
@Test public void shouldReturnUpdatedBookmarkAfterAutoCommitTransaction() throws Throwable { negotiateBoltV3(); // bookmark is expected to advance once the auto-commit transaction is committed long lastClosedTransactionId = getLastClosedTransactionId(); String expectedBookmark = new Bookmark( lastClosedTransactionId + 1 ).toString(); connection.send( util.chunk( new RunMessage( "CREATE ()" ), PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( allOf( hasEntry( "bookmark", expectedBookmark ) ) ) ) ); }