本文整理汇总了Java中com.amazonaws.services.simpledb.model.ReplaceableAttribute.setReplace方法的典型用法代码示例。如果您正苦于以下问题:Java ReplaceableAttribute.setReplace方法的具体用法?Java ReplaceableAttribute.setReplace怎么用?Java ReplaceableAttribute.setReplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.simpledb.model.ReplaceableAttribute
的用法示例。
在下文中一共展示了ReplaceableAttribute.setReplace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expectToAddOrDeleteRuleExclusionViaOptimisticPersister
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void expectToAddOrDeleteRuleExclusionViaOptimisticPersister(int expectedVersion,
String dateToExclude, Boolean doAdd, BookingRule ruleToAddExclusionTo) throws Exception {
// Set up attribute to be put to the database's booking rule item
ReplaceableAttribute replaceableAttribute = new ReplaceableAttribute();
replaceableAttribute.setName(getAttributeNameFromBookingRule(ruleToAddExclusionTo));
List<String> datesToExclude = new ArrayList<>();
datesToExclude.addAll(Arrays.asList(ruleToAddExclusionTo.getDatesToExclude()));
if (doAdd) {
datesToExclude.add(dateToExclude);
} else {
datesToExclude.remove(dateToExclude);
}
if (datesToExclude.size() > 0) {
replaceableAttribute.setValue(StringUtils.join(datesToExclude.toArray(), ","));
} else {
replaceableAttribute.setValue("");
}
replaceableAttribute.setReplace(true);
mockery.checking(new Expectations() {
{
oneOf(mockOptimisticPersister).put(with(equal(ruleItemName)),
with(Optional.of(expectedVersion)), with(equal(replaceableAttribute)));
}
});
}
示例2: testSetLifecycleStateCorrectlyCallsTheOptimisticPersister_retired_with_url
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Test
public void testSetLifecycleStateCorrectlyCallsTheOptimisticPersister_retired_with_url()
throws Exception {
// Tests happy path for setting RETIRED state - where we also supply a
// forwarding Url for the new site.
// ARRANGE
lifecycleManager.initialise(mockLogger);
// Set up a test lifecycle-state item - with an arbitrary version number.
ImmutablePair<Optional<Integer>, Set<Attribute>> testItem = new ImmutablePair<Optional<Integer>, Set<Attribute>>(
Optional.of(42), new HashSet<Attribute>());
ReplaceableAttribute newStateAttribute = new ReplaceableAttribute();
newStateAttribute.setName("State");
newStateAttribute.setValue("RETIRED");
newStateAttribute.setReplace(true);
ReplaceableAttribute newUrlAttribute = new ReplaceableAttribute();
newUrlAttribute.setName("Url");
newUrlAttribute.setValue(exampleForwardingUrl);
newUrlAttribute.setReplace(true);
mockery.checking(new Expectations() {
{
exactly(1).of(mockOptimisticPersister).get(with(equal("LifecycleState")));
will(returnValue(testItem));
exactly(1).of(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(42))), with(equal(newStateAttribute)));
will(returnValue(43));
exactly(1).of(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(43))), with(equal(newUrlAttribute)));
}
});
// ACT
lifecycleManager.setLifecycleState(LifecycleState.RETIRED, Optional.of(exampleForwardingUrl));
}
示例3: doTestSetLifecycleStateCorrectlyCallsTheOptimisticPersister
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void doTestSetLifecycleStateCorrectlyCallsTheOptimisticPersister(
LifecycleState lifecycleState) throws Exception {
// ARRANGE
lifecycleManager.initialise(mockLogger);
// Set up a test lifecycle-state item - with an arbitrary version number.
ImmutablePair<Optional<Integer>, Set<Attribute>> testItem = new ImmutablePair<Optional<Integer>, Set<Attribute>>(
Optional.of(42), new HashSet<Attribute>());
ReplaceableAttribute newStateAttribute = new ReplaceableAttribute();
newStateAttribute.setName("State");
newStateAttribute.setValue(lifecycleState.name());
newStateAttribute.setReplace(true);
mockery.checking(new Expectations() {
{
exactly(1).of(mockOptimisticPersister).get(with(equal("LifecycleState")));
will(returnValue(testItem));
exactly(1).of(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(42))), with(equal(newStateAttribute)));
// Don't want to put the Url attribute in this case - since we're not
// retiring.
never(mockOptimisticPersister).put(with(equal("LifecycleState")),
with(equal(Optional.of(43))), with(anything()));
}
});
// ACT
lifecycleManager.setLifecycleState(lifecycleState, Optional.empty());
}
示例4: setLifecycleState
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
@Override
public void setLifecycleState(LifecycleState lifecycleState, Optional<String> newServiceUrl)
throws Exception {
if (!initialised) {
throw new IllegalStateException("The lifecycle manager has not been initialised");
}
if (lifecycleState.equals(LifecycleState.RETIRED)) {
String message = null;
if (!newServiceUrl.isPresent() || !newServiceUrl.get().startsWith("http")) {
if (!newServiceUrl.isPresent()) {
message = "Throwing exception as url to new service has not been provided when setting lifecycle state to RETIRED";
} else if (!newServiceUrl.get().startsWith("http")) {
// Insist on correct format for the forwarding url.
message = "Throwing exception as url to new service when setting lifecycle state to RETIRED does not start with http";
}
logger.log(message);
throw new Exception(
"Must provide valid url to new service when setting lifecycle state to RETIRED");
}
}
// Get attribute - so can set version correctly. We assume only one person
// (i.e. the site admin) will ever be calling this at one time, but we
// nevertheless supply the version - so we can use the optimistic persister.
ImmutablePair<Optional<Integer>, Set<Attribute>> lifecycleStateItem = getOptimisticPersister()
.get(lifecycleItemName);
logger.log("About to set lifecycle state in database to: " + lifecycleState.name());
ReplaceableAttribute lifecycleAttribute = new ReplaceableAttribute();
lifecycleAttribute.setName("State");
lifecycleAttribute.setValue(lifecycleState.name());
lifecycleAttribute.setReplace(true);
int newVersion = getOptimisticPersister().put(lifecycleItemName, lifecycleStateItem.left,
lifecycleAttribute);
logger.log("Updated lifecycle state in database to: " + lifecycleState.name());
if (newServiceUrl.isPresent()) {
logger.log("About to set lifecycle state url in database to: " + newServiceUrl.get());
ReplaceableAttribute urlAttribute = new ReplaceableAttribute();
urlAttribute.setName("Url");
urlAttribute.setValue(newServiceUrl.get());
urlAttribute.setReplace(true);
getOptimisticPersister().put(lifecycleItemName, Optional.of(newVersion), urlAttribute);
logger.log("Updated lifecycle state url in database to: " + newServiceUrl.get());
}
}
示例5: doTestPutUsesCorrectVersionWhenCallingTheDatabase
import com.amazonaws.services.simpledb.model.ReplaceableAttribute; //导入方法依赖的package包/类
private void doTestPutUsesCorrectVersionWhenCallingTheDatabase(Optional<Integer> version)
throws Exception {
// ARRANGE
initialiseOptimisticPersister();
// Configure attributes for database to return - the get is used for logging
// only, so does not really matter.
GetAttributesRequest simpleDBRequest = new GetAttributesRequest(testSimpleDBDomainName,
testItemName);
simpleDBRequest.setConsistentRead(true);
GetAttributesResult getAttributesResult = new GetAttributesResult();
mockery.checking(new Expectations() {
{
allowing(mockSimpleDBClient).getAttributes(with(equal(simpleDBRequest)));
will(returnValue(getAttributesResult));
}
});
// Configure expectations for the put:
UpdateCondition updateCondition = new UpdateCondition();
updateCondition.setName(versionAttributeName);
ReplaceableAttribute versionAttribute = new ReplaceableAttribute();
versionAttribute.setName(versionAttributeName);
versionAttribute.setReplace(true);
if (!version.isPresent()) {
// A version number attribute did not exist - so it still should not
updateCondition.setExists(false);
// Set initial value for our version number attribute
versionAttribute.setValue("0");
} else {
// A version number attribute exists - so it should be unchanged
updateCondition.setValue(Integer.toString(version.get()));
// Bump up our version number attribute
versionAttribute.setValue(Integer.toString(version.get() + 1));
}
List<ReplaceableAttribute> replaceableAttributes = new ArrayList<>();
replaceableAttributes.add(versionAttribute);
// Add the new attribute
ReplaceableAttribute testAttribute = new ReplaceableAttribute();
testAttribute.setName("Name");
testAttribute.setValue("Value");
replaceableAttributes.add(testAttribute);
PutAttributesRequest simpleDBPutRequest = new PutAttributesRequest(testSimpleDBDomainName,
testItemName, replaceableAttributes, updateCondition);
mockery.checking(new Expectations() {
{
oneOf(mockSimpleDBClient).putAttributes(with(equal(simpleDBPutRequest)));
}
});
// ACT
optimisticPersister.put(testItemName, version, testAttribute);
}