Java 类com.amazonaws.util.ImmutableMapParameter 实例源码

项目:ibm-cos-sdk-java    文件:AwsProfileRegionProviderTest.java   
@Test
public void profilesNonEmptyButGivenProfileNotPresent_ProvidesNullRegion() {
    final String otherProfileName = "other_profile";
    final BasicProfile other_profile = new BasicProfile(otherProfileName, ImmutableMapParameter
            .of(ProfileKeyConstants.REGION, "us-east-8"));
    final AllProfiles profiles = new AllProfiles(
            ImmutableMapParameter.of(otherProfileName, other_profile));
    stubLoadProfile(profiles);
    assertNull(regionProvider.getRegion());
}
项目:ibm-cos-sdk-java    文件:AwsProfileRegionProviderTest.java   
@Test
public void profilePresentButRegionIsNotSet_ProvidesNullRegion() {
    final BasicProfile profile = new BasicProfile(PROFILE, new HashMap<String, String>());
    final AllProfiles profiles = new AllProfiles(ImmutableMapParameter.of(PROFILE, profile));
    stubLoadProfile(profiles);
    assertNull(regionProvider.getRegion());
}
项目:ibm-cos-sdk-java    文件:AwsProfileRegionProviderTest.java   
@Test
public void profilePresentButRegionIsEmpty_ProvidesNullRegion() {
    final BasicProfile profile = new BasicProfile(PROFILE, ImmutableMapParameter
            .of(ProfileKeyConstants.REGION, ""));
    final AllProfiles profiles = new AllProfiles(ImmutableMapParameter.of(PROFILE, profile));
    stubLoadProfile(profiles);
    assertNull(regionProvider.getRegion());
}
项目:ibm-cos-sdk-java    文件:AwsProfileRegionProviderTest.java   
@Test
public void profilePresentAndRegionIsSet_ProvidesCorrectRegion() {
    final String expectedRegion = "us-east-8";
    final BasicProfile profile = new BasicProfile(PROFILE, ImmutableMapParameter
            .of(ProfileKeyConstants.REGION, expectedRegion));
    final AllProfiles profiles = new AllProfiles(ImmutableMapParameter.of(PROFILE, profile));
    stubLoadProfile(profiles);
    assertEquals(expectedRegion, regionProvider.getRegion());
}
项目:ibm-cos-sdk-java    文件:ImmutableMapParameterTest.java   
@Test
public void testMapBuilder() {
    Map<Integer, String> builtMap = new ImmutableMapParameter.Builder<Integer, String>()
                                            .put(1, "one")
                                            .put(2, "two")
                                            .put(3, "three")
                                            .build();
    assertEquals(3, builtMap.size());
    assertEquals("one", builtMap.get(1));
    assertEquals("two", builtMap.get(2));
    assertEquals("three", builtMap.get(3));
}
项目:ibm-cos-sdk-java    文件:ImmutableMapParameterTest.java   
@Test
public void testOfBuilder() {
    Map<Integer, String> builtMap = ImmutableMapParameter.of(1, "one");
    assertEquals(1, builtMap.size());
    assertEquals("one", builtMap.get(1));
    builtMap = ImmutableMapParameter.of(1, "one", 2, "two");
    assertEquals(2, builtMap.size());
    assertEquals("one", builtMap.get(1));
    assertEquals("two", builtMap.get(2));
    builtMap = ImmutableMapParameter.of(1, "one", 2, "two", 3, "three");
    assertEquals(3, builtMap.size());
    assertEquals("one", builtMap.get(1));
    assertEquals("two", builtMap.get(2));
    assertEquals("three", builtMap.get(3));
    builtMap = ImmutableMapParameter.of(1, "one", 2, "two", 3, "three", 4, "four");
    assertEquals(4, builtMap.size());
    assertEquals("one", builtMap.get(1));
    assertEquals("two", builtMap.get(2));
    assertEquals("three", builtMap.get(3));
    assertEquals("four", builtMap.get(4));
    builtMap = ImmutableMapParameter.of(1, "one", 2, "two", 3, "three", 4, "four", 5, "five");
    assertEquals(5, builtMap.size());
    assertEquals("one", builtMap.get(1));
    assertEquals("two", builtMap.get(2));
    assertEquals("three", builtMap.get(3));
    assertEquals("four", builtMap.get(4));
    assertEquals("five", builtMap.get(5));
}
项目:ibm-cos-sdk-java    文件:ImmutableMapParameterTest.java   
@Test
public void testErrorOnDuplicateKeys() {
    try {
        Map<Integer, String> builtMap = new ImmutableMapParameter.Builder<Integer, String>()
                .put(1, "one")
                .put(1, "two")
                .build();
        fail("IllegalArgumentException expected.");
    } catch (IllegalArgumentException iae) {
    } catch (Exception e) {
        fail("IllegalArgumentException expected.");
    }
}
项目:PlatePicks-Android    文件:TableFood.java   
/**
     * Inserting the food into the database, dislike and like are set to 0
     * @param food
     */
    public static void insertFood(FoodReceive food){
        Log.d(LOG_TAG, "Inserting: " + food.getName());
        final DynamoDBMapper mapper = AWSMobileClient.defaultMobileClient().getDynamoDBMapper();
        final FoodDO firstItem = new FoodDO();

        firstItem.setFoodId(food.getFood_id());
        firstItem.setRestaurantId(food.getLocation().getRestaurantId());
        firstItem.setName(food.getName());

        AmazonClientException lastException = null;
        DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression();
        Map<String, ExpectedAttributeValue> expectedAttributes =
                ImmutableMapParameter.<String, ExpectedAttributeValue>builder()
                        .put("foodId", new ExpectedAttributeValue(false)).build();
        saveExpression.setExpected(expectedAttributes);

        try {
//            mapper.save(firstItem);
            mapper.save(firstItem, saveExpression);
        } catch (ConditionalCheckFailedException e){
            Log.e(LOG_TAG,"The foodId exists: " + e.getMessage());
            lastException = e;
        } catch (final AmazonClientException ex) {
            Log.e(LOG_TAG,"Failed saving item batch: " + ex.getMessage());
            lastException = ex;
        }

        if (lastException != null) {
            // Re-throw the last exception encountered to alert the user.
            throw lastException;
        }

        Log.d(LOG_TAG, "Insert successful");
    }
项目:aws-sdk-java-resources    文件:SQSResourcesIntegrationTest.java   
/**
 * Tests sending of message with message attributes. Asserts that the
 * message received has the attributes. Also changes the visibility of the
 * messages and tries to retrieve them. Performs delete action on the
 * message to the delete it from the queue.
 */
@Test
@Ignore
public void testSendReceiveMessageAttributes() throws InterruptedException {

    SendMessageResult sendMessageResult = queue
            .sendMessage(new SendMessageRequest().withMessageBody(
                    TEST_MESSAGE_ATTRIBUTES).withMessageAttributes(
                    ImmutableMapParameter.of(
                            "testAttribute",
                            new MessageAttributeValue().withDataType(
                                    "String").withStringValue(
                                    "testAttributeValue"))));

    List<Message> messages = waitForMessagesFromQueue(new ReceiveMessageRequest()
            .withMessageAttributeNames("testAttribute"));

    assertNotNull(messages);
    assertEquals(1, messages.size());
    Message message = messages.get(0);
    assertMessage(TEST_MESSAGE_ATTRIBUTES,
            sendMessageResult.getMessageId(),
            sendMessageResult.getMD5OfMessageBody(), message);

    Map<String, MessageAttributeValue> messageAttributes = message
            .getMessageAttributes();
    assertNotNull(messageAttributes);
    assertTrue(messageAttributes.containsKey("testAttribute"));
    assertEquals(messageAttributes.get("testAttribute").getStringValue(),
            "testAttributeValue");

    message.changeVisibility(10);

    messages = waitForMessagesFromQueue(null);
    message.delete();
}
项目:aws-sdk-java-resources    文件:SQSResourcesIntegrationTest.java   
/**
 * Tests sending messages using batch operation and retrieve them. Also
 * tests setting the queue attributes and retrieving them.
 */
@Test
@Ignore
public void testQueueSubResourceAndAttributes() throws InterruptedException {

    /**
     * Trying to get the message which is deleted. Here there is no service
     * call made, a new sub resource is created with the given handle. So,
     * this wont be returning null.
     */
    Message message = queue.getMessage("invalid-recepient-handle");
    assertNotNull(message);
    try {
        message.getAttributes();
        fail("An unsupported operation exception must be thrown as load operation is no supported on message attribute");
    } catch (UnsupportedOperationException use) { }

    SendMessageBatchResult sendMessageBatchResult = queue
            .sendMessages(new SendMessageBatchRequest()
                    .withEntries(new SendMessageBatchRequestEntry("msg1",
                            TEST_MESSAGE)));
    SendMessageBatchResultEntry sendMessageBatchResultEntry = sendMessageBatchResult
            .getSuccessful().get(0);
    List<Message> messages = waitForMessagesFromQueue(null);

    assertNotNull(messages);
    assertEquals(1, messages.size());
    message = messages.get(0);
    assertMessage(TEST_MESSAGE, sendMessageBatchResultEntry.getMessageId(),
            sendMessageBatchResultEntry.getMD5OfMessageBody(), message);

    queue.setAttributes(ImmutableMapParameter.of("MaximumMessageSize",
            "2048"));

    assertTrue(queue.getAttributes().containsKey("MaximumMessageSize"));
}
项目:ibm-cos-sdk-java    文件:ProfilesConfigFileWriterTest.java   
/**
 * Tests that comments and unsupported properties are preserved after
 * profile modification.
 * @throws URISyntaxException
 */
@Test
public void testModifyAndInsertProfile_WithComments() throws IOException, URISyntaxException {
    File credWithComments = ProfileResourceLoader.profilesWithComments().asFile();
    File tmpFile = copyToTempFile(credWithComments);

    String originalContent = FileUtils.readFileToString(tmpFile);

    Profile[] expected = {
            new Profile("a", basicCredA),
            new Profile("b", basicCredB),
            new Profile("c", sessionCredC),
            new Profile("d", sessionCredD)
            };

    // a <==> b, c <==> d, also renaming them to uppercase letters
    Profile[] modified = {
            new Profile("A", basicCredB),
            new Profile("B", basicCredA),
            new Profile("C", sessionCredD),
            new Profile("D", sessionCredC)
            };
    ProfilesConfigFileWriter.modifyProfiles(tmpFile, ImmutableMapParameter
            .of("a", modified[0],
                "b", modified[1],
                "c", modified[2],
                "d", modified[3]));
    checkCredentialsFile(tmpFile, modified);

    // Sanity check that the content is altered
    String modifiedContent = FileUtils.readFileToString(tmpFile);
    assertFalse(originalContent.equals(modifiedContent));

    // Restore the properties
    ProfilesConfigFileWriter.modifyProfiles(tmpFile, ImmutableMapParameter
            .of("A", expected[0],
                "B", expected[1],
                "C", expected[2],
                "D", expected[3]));
    checkCredentialsFile(tmpFile, expected);

    // Check that the content is now the same as the original
    String restoredContent = FileUtils.readFileToString(tmpFile);
    assertEquals(originalContent, restoredContent);
}
项目:ibm-cos-sdk-java    文件:ClientConfigurationTest.java   
@Test
@Ignore
public void clientConfigurationCopyConstructor_CopiesAllValues() throws Exception {
    ClientConfiguration customConfig = new ClientConfiguration();

    for (Field field : ClientConfiguration.class.getDeclaredFields()) {
        if (isStaticField(field)) {
            continue;
        }
        field.setAccessible(true);
        final Class<?> clzz = field.getType();

        if (clzz.isAssignableFrom(int.class) || clzz.isAssignableFrom(long.class)) {
            field.set(customConfig, Math.abs(RANDOM.nextInt()));
        } else if (clzz.isAssignableFrom(boolean.class)) {
            // Invert the default value to ensure it's different
            field.set(customConfig, !(Boolean) field.get(customConfig));
        } else if (clzz.isAssignableFrom(String.class)) {
            field.set(customConfig, RandomStringUtils.random(10));
        } else if (clzz.isAssignableFrom(RetryPolicy.class)) {
            field.set(customConfig, CUSTOM_RETRY_POLICY);
        } else if (clzz.isAssignableFrom(InetAddress.class)) {
            field.set(customConfig, InetAddress.getLocalHost());
        } else if (clzz.isAssignableFrom(Protocol.class)) {
            // Default is HTTPS so switch to HTTP
            field.set(customConfig, Protocol.HTTP);
        } else if (clzz.isAssignableFrom(DnsResolver.class)) {
            field.set(customConfig, new MyCustomDnsResolver());
        } else if (clzz.isAssignableFrom(SecureRandom.class)) {
            field.set(customConfig, new SecureRandom());
        } else if (field.getName().equals("headers")) {
            field.set(customConfig, ImmutableMapParameter.of("foo", "bar"));
        } else if (clzz.isAssignableFrom(ApacheHttpClientConfig.class)) {
            customConfig.getApacheHttpClientConfig()
                        .setSslSocketFactory(Mockito.mock(ConnectionSocketFactory.class));
        } else if (clzz.isAssignableFrom(List.class)) {
            field.set(customConfig, new ArrayList<Object>());
        } else {
            throw new RuntimeException(
                    String.format("Field %s of type %s is not supported",
                                  field.getName(),
                                  field.getType()));
        }
        // Extra check to make sure the value differs from the default and we haven't missed something
        assertNotEquals(
                String.format("Field %s does not differ from default value", field.getName()),
                field.get(DEFAULT_CLIENT_CONFIG), field.get(customConfig));
    }

    // Do a deep comparison of the config after sending it through the copy constructor
    assertReflectionEquals(customConfig, new ClientConfiguration(customConfig));
}