Java Code Examples for org.assertj.core.util.Maps#newHashMap()

The following examples show how to use org.assertj.core.util.Maps#newHashMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouteBuilderTests.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
@Test
public void testRouteOptionsPropagatedToRoute() {
	Map<String, Object> routeMetadata = Maps.newHashMap("key", "value");
	RouteLocator routeLocator = this.routeLocatorBuilder.routes()
			.route("test1", r -> r.host("*.somehost.org").and().path("/somepath")
					.filters(f -> f.addRequestHeader("header1", "header-value-1"))
					.metadata("key", "value").uri("http://someuri"))
			.route("test2", r -> r.host("*.somehost2.org")
					.filters(f -> f.addResponseHeader("header-response-1",
							"header-response-1"))
					.uri("https://httpbin.org:9090"))
			.build();

	StepVerifier.create(routeLocator.getRoutes())
			.expectNextMatches(
					r -> r.getId().equals("test1") && r.getFilters().size() == 1
							&& r.getUri().equals(URI.create("http://someuri:80"))
							&& r.getMetadata().equals(routeMetadata))
			.expectNextMatches(r -> r.getId().equals("test2")
					&& r.getFilters().size() == 1
					&& r.getUri().equals(URI.create("https://httpbin.org:9090"))
					&& r.getMetadata().isEmpty())
			.expectComplete().verify();
}
 
Example 2
Source File: HeaderEntryFiltersTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void toExternalHeadersFilterDiscardsDittoInternalAckRequests() {
    final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS;
    final Map<String, HeaderDefinition> headerDefinitions =
            Maps.newHashMap(headerDefinition.getKey(), headerDefinition);
    final List<AcknowledgementRequest> allAcknowledgementRequests = Lists.list(
            AcknowledgementRequest.of(AcknowledgementLabel.of("foo")),
            AcknowledgementRequest.of(DittoAcknowledgementLabel.TWIN_PERSISTED),
            AcknowledgementRequest.of(AcknowledgementLabel.of("bar")));
    final JsonArray allAcknowledgementRequestsJsonArray = allAcknowledgementRequests.stream()
            .map(AcknowledgementRequest::toString)
            .map(JsonValue::of)
            .collect(JsonCollectors.valuesToArray());
    final String value = allAcknowledgementRequestsJsonArray.toString();
    final JsonArray externalAcknowledgementRequests = allAcknowledgementRequestsJsonArray.toBuilder()
            .remove(1)
            .build();
    final String expected = externalAcknowledgementRequests.toString();

    final HeaderEntryFilter underTest = HeaderEntryFilters.toExternalHeadersFilter(headerDefinitions);

    assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(expected);
}
 
Example 3
Source File: AssertJDogTest.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
@Test(description = "Map断言")
public void whenGivenMap_then() {
	Map<Integer, String> map = Maps.newHashMap(2, "a");

	// 断言Map是否为空,包含key “2”,不包含key “10” 并包含元素:key:2,value:“a”
	assertThat(map).isNotEmpty().containsKey(2).doesNotContainKeys(10).contains(entry(2, "a"));
}
 
Example 4
Source File: ClientConfigTest.java    From xio with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuilderCustomValues() {
  Config config = ConfigFactory.load();
  ClientConfig fallbackObject = ClientConfig.from(config.getConfig("xio.clientTemplate"));
  Map expectedBootstrapOptions = Maps.newHashMap(ChannelOption.AUTO_READ, new Object());
  TlsConfig expectedTls = TlsConfig.builderFrom(ConfigFactory.load("tls-reference")).build();
  boolean expectedMessageLoggerEnabled = true;
  InetSocketAddress expectedLocal = new InetSocketAddress("local ip", 11111);
  InetSocketAddress expectedRemote = new InetSocketAddress("remote ip", 22222);
  IdleTimeoutConfig expectedIdleTimeoutConfig = new IdleTimeoutConfig(true, 55);

  ClientConfig subject =
      ClientConfig.newBuilder(fallbackObject)
          .setBootstrapOptions(expectedBootstrapOptions)
          .setTls(expectedTls)
          .setMessageLoggerEnabled(expectedMessageLoggerEnabled)
          .setLocal(expectedLocal)
          .setRemote(expectedRemote)
          .setIdleTimeoutConfig(expectedIdleTimeoutConfig)
          .build();

  assertEquals(expectedBootstrapOptions, subject.bootstrapOptions());
  assertEquals(expectedTls, subject.tls());
  assertEquals(expectedMessageLoggerEnabled, subject.messageLoggerEnabled());
  assertEquals(expectedLocal, subject.local());
  assertEquals(expectedRemote, subject.remote());
  assertEquals(expectedIdleTimeoutConfig, subject.idleTimeoutConfig());
}
 
Example 5
Source File: RouteDefinitionTest.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void addSingleMetadataEntryKeepsOriginalMetadata() {
	Map<String, Object> originalMetadata = Maps.newHashMap("key", "value");

	RouteDefinition routeDefinition = new RouteDefinition();
	routeDefinition.setMetadata(originalMetadata);
	routeDefinition.getMetadata().put("key2", "value2");

	assertThat(routeDefinition.getMetadata()).hasSize(2)
			.containsAllEntriesOf(originalMetadata).containsEntry("key2", "value2");
}
 
Example 6
Source File: RouteDefinitionTest.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void setRouteDefinitionReplacesExistingMetadata() {
	Map<String, Object> originalMetadata = Maps.newHashMap("key", "value");
	Map<String, Object> newMetadata = Maps.newHashMap("key2", "value2");

	RouteDefinition routeDefinition = new RouteDefinition();
	routeDefinition.setMetadata(originalMetadata);
	routeDefinition.setMetadata(newMetadata);

	assertThat(routeDefinition.getMetadata()).isEqualTo(newMetadata);
}
 
Example 7
Source File: RouteDefinitionTest.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void addRouteDefinitionKeepsExistingMetadata() {
	Map<String, Object> originalMetadata = Maps.newHashMap("key", "value");
	Map<String, Object> newMetadata = Maps.newHashMap("key2", "value2");

	RouteDefinition routeDefinition = new RouteDefinition();
	routeDefinition.setMetadata(originalMetadata);
	routeDefinition.getMetadata().putAll(newMetadata);

	assertThat(routeDefinition.getMetadata()).hasSize(2)
			.containsAllEntriesOf(originalMetadata).containsAllEntriesOf(newMetadata);
}
 
Example 8
Source File: CheckExternalFilterTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void filterValueThatShouldNotBeExposedExternally() {
    final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.DRY_RUN;
    final Map<String, HeaderDefinition> headerDefinitions =
            Maps.newHashMap(headerDefinition.getKey(), headerDefinition);
    final CheckExternalFilter underTest = CheckExternalFilter.shouldWriteToExternal(headerDefinitions);

    assertThat(underTest.apply(headerDefinition.getKey(), "true")).isNull();
}
 
Example 9
Source File: CheckExternalFilterTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void filterValueThatShouldBeExposedExternally() {
    final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.CORRELATION_ID;
    final String value = "correlation-id";
    final Map<String, HeaderDefinition> headerDefinitions =
            Maps.newHashMap(headerDefinition.getKey(), headerDefinition);
    final CheckExternalFilter underTest = CheckExternalFilter.shouldWriteToExternal(headerDefinitions);

    assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(value);
}
 
Example 10
Source File: CheckExternalFilterTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void filterValueThatShouldNotBeReadFromExternal() {
    final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.DRY_RUN;
    final Map<String, HeaderDefinition> headerDefinitions =
            Maps.newHashMap(headerDefinition.getKey(), headerDefinition);
    final CheckExternalFilter underTest = CheckExternalFilter.shouldReadFromExternal(headerDefinitions);

    assertThat(underTest.apply(headerDefinition.getKey(), "true")).isNull();
}
 
Example 11
Source File: CheckExternalFilterTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void filterValueThatShouldBeReadFromExternal() {
    final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.CORRELATION_ID;
    final String value = "correlation-id";
    final Map<String, HeaderDefinition> headerDefinitions =
            Maps.newHashMap(headerDefinition.getKey(), headerDefinition);
    final CheckExternalFilter underTest = CheckExternalFilter.shouldReadFromExternal(headerDefinitions);

    assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(value);
}
 
Example 12
Source File: AdditionalPropertiesTest.java    From OpenYOLO-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuild_setAdditionalProperty_nullValue() {
    final Map<String, byte[]> mapWithNullValue = Maps.newHashMap("a", null);


    assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            mBuilder.setAdditionalProperties(mapWithNullValue);
        }
    }).isInstanceOf(IllegalArgumentException.class);
}
 
Example 13
Source File: AdditionalPropertiesTest.java    From OpenYOLO-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuilder_setAdditionalProperties_nullKey() {
    final Map<String, byte[]> mapWithNullKey = Maps.newHashMap(null, new byte[0]);
    assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            mBuilder.setAdditionalProperties(mapWithNullKey);
        }
    }).isInstanceOf(IllegalArgumentException.class);
}
 
Example 14
Source File: AbstractOAuth2TokenServiceTest.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
@Test
public void requestAccessToken_sameAdditionalParameters_onlyOneRequestCall() throws OAuth2ServiceException {
	Map<String, String> parameters = Maps.newHashMap("a", "b");
	parameters.put("c", "d");
	Map<String, String> sameParametersDifferentOrder = Maps.newHashMap("c", "d");
	sameParametersDifferentOrder.put("a", "b");

	retrieveAccessTokenViaJwtBearerTokenGrant("token", parameters);
	retrieveAccessTokenViaJwtBearerTokenGrant("token", sameParametersDifferentOrder);

	assertThat(cut.tokenRequestCallCount).isOne();
}
 
Example 15
Source File: PasswordTokenFlowTest.java    From cloud-security-xsuaa-integration with Apache License 2.0 5 votes vote down vote up
@Test
public void additionalParametersAreUsed() throws Exception {
	String key = "aKey";
	String value = "aValue";
	Map<String, String> givenParameters = Maps.newHashMap(key, value);
	Map<String, String> equalParameters = Maps.newHashMap(key, value);

	createValidRequest().optionalParameters(givenParameters).execute();

	verify(tokenService, times(1))
			.retrieveAccessTokenViaPasswordGrant(any(), any(), any(),
					any(), any(), eq(equalParameters), anyBoolean());
}
 
Example 16
Source File: PointDictServiceTest.java    From sds with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckAndDelete(){
    for(int i = 0; i< 11; i++){
        Map<String, SdsCycleInfo> map = Maps.newHashMap("1", new SdsCycleInfo());

        pointDictService.checkAndDeleteDeadPoint(map, "1", "1");
    }
}
 
Example 17
Source File: ReadJsonArrayHeadersFilterTest.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    headerDefinitions = Maps.newHashMap(HEADER_DEFINITION.getKey(), HEADER_DEFINITION);
}
 
Example 18
Source File: FrameSerializerTest.java    From simulacron with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleFrameWarningsAndCustomPayload() throws Exception {
  UUID uuid = UUID.fromString("ce565629-e8e4-4f93-bdd4-9414b7d9d342");
  // 0x0708 == Bwg= base64 encoded
  Map<String, ByteBuffer> customPayload =
      Maps.newHashMap("custom", ByteBuffer.wrap(new byte[] {0x7, 0x8}));
  Frame frame =
      new Frame(
          5,
          true,
          10,
          true,
          uuid,
          customPayload,
          Lists.newArrayList("Something went wrong", "Fix me!"),
          com.datastax.oss.protocol.internal.request.Options.INSTANCE);

  String json = writer.writeValueAsString(frame);
  assertThat(json)
      .isEqualTo(
          "{"
              + System.lineSeparator()
              + "  \"protocol_version\" : 5,"
              + System.lineSeparator()
              + "  \"beta\" : true,"
              + System.lineSeparator()
              + "  \"stream_id\" : 10,"
              + System.lineSeparator()
              + "  \"tracing_id\" : \"ce565629-e8e4-4f93-bdd4-9414b7d9d342\","
              + System.lineSeparator()
              + "  \"custom_payload\" : {"
              + System.lineSeparator()
              + "    \"custom\" : \"Bwg=\""
              + System.lineSeparator()
              + "  },"
              + System.lineSeparator()
              + "  \"warnings\" : [ \"Something went wrong\", \"Fix me!\" ],"
              + System.lineSeparator()
              + "  \"message\" : {"
              + System.lineSeparator()
              + "    \"type\" : \"OPTIONS\","
              + System.lineSeparator()
              + "    \"opcode\" : 5,"
              + System.lineSeparator()
              + "    \"is_response\" : false"
              + System.lineSeparator()
              + "  }"
              + System.lineSeparator()
              + "}");
}
 
Example 19
Source File: StackDecoratorTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    String credentialName = "credentialName";
    MockitoAnnotations.initMocks(this);
    subject = new Stack();
    subject.setEnvironmentCrn("envCrn");
    Set<InstanceGroup> instanceGroups = createInstanceGroups(GATEWAY);
    subject.setInstanceGroups(instanceGroups);
    Cluster cluster = getCluster(instanceGroups);
    subject.setCluster(cluster);
    subject.setCloudPlatform("AZURE");
    subject.setParameters(new HashMap<>());
    when(cloudParameterCache.getPlatformParameters()).thenReturn(platformParametersMap);
    when(platformParametersMap.get(any(Platform.class))).thenReturn(pps);
    when(pps.specialParameters()).thenReturn(specialParameters);
    when(specialParameters.getSpecialParameters()).thenReturn(specialParametersMap);
    when(specialParametersMap.get(anyString())).thenReturn(false);
    when(cloudParameterService.getOrchestrators()).thenReturn(platformOrchestrators);
    when(platformOrchestrators.getDefaults()).thenReturn(defaultOrchestrator);
    when(defaultOrchestrator.get(any(Platform.class))).thenReturn(orchestrator);
    when(converterUtil.convert(any(InstanceGroup.class), eq(InstanceGroupParameterRequest.class))).thenReturn(instanceGroupParameterRequest);
    when(request.getCluster()).thenReturn(clusterRequest);
    when(environmentSettingsRequest.getCredentialName()).thenReturn(credentialName);
    when(sharedServiceValidator.checkSharedServiceStackRequirements(any(StackV4Request.class), any(Workspace.class))).thenReturn(validationResult);
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCredential(credentialResponse);
    CompactRegionResponse crr = new CompactRegionResponse();
    crr.setNames(Lists.newArrayList("region"));
    environmentResponse.setRegions(crr);
    EnvironmentNetworkResponse enr = new EnvironmentNetworkResponse();
    Map<String, CloudSubnet> subnetmetas = Maps.newHashMap("subnet", new CloudSubnet("id", "name", "availabilityzone", "cidr"));
    enr.setSubnetMetas(subnetmetas);
    environmentResponse.setNetwork(enr);
    environmentResponse.setAzure(AzureEnvironmentParameters
            .builder().withAzureResourceGroup(AzureResourceGroup
                    .builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName("resource-group").build()).build());
    when(request.getCloudPlatform()).thenReturn(CloudPlatform.AZURE);
    when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    Credential credential = Credential.builder().cloudPlatform(CloudPlatform.MOCK.name()).build();
    when(credentialClientService.getByCrn(anyString())).thenReturn(credential);
    when(credentialClientService.getByName(anyString())).thenReturn(credential);
    when(credentialConverter.convert(credentialResponse)).thenReturn(credential);
    ExtendedCloudCredential extendedCloudCredential = mock(ExtendedCloudCredential.class);
    when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCloudCredential);
}
 
Example 20
Source File: AssertJCoreUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenGivenMap_then() throws Exception {
    Map<Integer, String> map = Maps.newHashMap(2, "a");

    assertThat(map).isNotEmpty().containsKey(2).doesNotContainKeys(10).contains(entry(2, "a"));
}