本文整理汇总了Java中com.neovisionaries.i18n.CountryCode类的典型用法代码示例。如果您正苦于以下问题:Java CountryCode类的具体用法?Java CountryCode怎么用?Java CountryCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CountryCode类属于com.neovisionaries.i18n包,在下文中一共展示了CountryCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveCustomTypeReference_WithKeyAsUuidSetAndNotAllowed_ShouldNotResolveCustomTypeReference
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveCustomTypeReference_WithKeyAsUuidSetAndNotAllowed_ShouldNotResolveCustomTypeReference() {
final CustomFieldsDraft customFieldsDraft = CustomFieldsDraft
.ofTypeIdAndJson(UUID.randomUUID().toString(), new HashMap<>());
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.custom(customFieldsDraft);
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
assertThat(priceReferenceResolver.resolveCustomTypeReference(priceBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve custom type reference on PriceDraft"
+ " with country:'DE' and value: 'EUR 10.00000'. Reason: Found a UUID"
+ " in the id field. Expecting a key without a UUID value. If you want to"
+ " allow UUID values for reference keys, please use the "
+ "allowUuidKeys(true) option in the sync options.");
}
示例2: resolveCustomTypeReference_WithNonExistentCustomType_ShouldNotResolveCustomTypeReference
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveCustomTypeReference_WithNonExistentCustomType_ShouldNotResolveCustomTypeReference() {
final String customTypeKey = "customTypeKey";
final CustomFieldsDraft customFieldsDraft = CustomFieldsDraft.ofTypeIdAndJson(customTypeKey, new HashMap<>());
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.custom(customFieldsDraft);
when(typeService.fetchCachedTypeId(anyString()))
.thenReturn(CompletableFuture.completedFuture(Optional.empty()));
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
assertThat(priceReferenceResolver.resolveCustomTypeReference(priceBuilder).toCompletableFuture())
.hasNotFailed()
.isCompletedWithValueMatching(resolvedDraft ->
Objects.nonNull(resolvedDraft.getCustom())
&& Objects.nonNull(resolvedDraft.getCustom().getType())
&& Objects.equals(resolvedDraft.getCustom().getType().getId(), customTypeKey));
}
示例3: resolveCustomTypeReference_WithNullIdOnCustomTypeReference_ShouldNotResolveCustomTypeReference
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveCustomTypeReference_WithNullIdOnCustomTypeReference_ShouldNotResolveCustomTypeReference() {
final CustomFieldsDraft customFieldsDraft = mock(CustomFieldsDraft.class);
final ResourceIdentifier<Type> typeReference = ResourceIdentifier.ofId(null);
when(customFieldsDraft.getType()).thenReturn(typeReference);
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.custom(customFieldsDraft);
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
assertThat(priceReferenceResolver.resolveCustomTypeReference(priceBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve custom type reference on PriceDraft"
+ " with country:'DE' and value: 'EUR 10.00000'. Reason: Reference 'id' field"
+ " value is blank (null/empty).");
}
示例4: resolveCustomTypeReference_WithEmptyIdOnCustomTypeReference_ShouldNotResolveCustomTypeReference
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveCustomTypeReference_WithEmptyIdOnCustomTypeReference_ShouldNotResolveCustomTypeReference() {
final CustomFieldsDraft customFieldsDraft = CustomFieldsDraft.ofTypeIdAndJson("", new HashMap<>());
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.custom(customFieldsDraft);
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
assertThat(priceReferenceResolver.resolveCustomTypeReference(priceBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve custom type reference on PriceDraft"
+ " with country:'DE' and value: 'EUR 10.00000'. Reason: Reference 'id' field"
+ " value is blank (null/empty).");
}
示例5: resolveCustomTypeReference_WithExceptionOnCustomTypeFetch_ShouldNotResolveReferences
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveCustomTypeReference_WithExceptionOnCustomTypeFetch_ShouldNotResolveReferences() {
final String customTypeKey = "customTypeKey";
final CustomFieldsDraft customFieldsDraft = CustomFieldsDraft.ofTypeIdAndJson(customTypeKey, new HashMap<>());
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.custom(customFieldsDraft);
final CompletableFuture<Optional<String>> futureThrowingSphereException = new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new SphereException("CTP error on fetch"));
when(typeService.fetchCachedTypeId(anyString())).thenReturn(futureThrowingSphereException);
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
assertThat(priceReferenceResolver.resolveCustomTypeReference(priceBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(SphereException.class)
.hasMessageContaining("CTP error on fetch");
}
示例6: resolveChannelReference_WithChannelKeyAsUuidSetAndAllowed_ShouldResolveChannelReference
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveChannelReference_WithChannelKeyAsUuidSetAndAllowed_ShouldResolveChannelReference() {
final ProductSyncOptions productSyncOptions = ProductSyncOptionsBuilder.of(mock(SphereClient.class))
.allowUuidKeys(true)
.build();
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.channel(Channel.referenceOfId(UUID.randomUUID().toString()));
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(productSyncOptions, typeService, channelService);
final PriceDraftBuilder resolvedBuilder = priceReferenceResolver.resolveChannelReference(priceBuilder)
.toCompletableFuture().join();
assertThat(resolvedBuilder.getChannel()).isNotNull();
assertThat(resolvedBuilder.getChannel().getId()).isEqualTo(CHANNEL_ID);
}
示例7: resolveChannelReference_WithChannelKeyAsUuidSetAndNotAllowed_ShouldNotResolveChannelReference
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveChannelReference_WithChannelKeyAsUuidSetAndNotAllowed_ShouldNotResolveChannelReference() {
final PriceDraftBuilder priceBuilder = PriceDraftBuilder
.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.channel(Channel.referenceOfId(UUID.randomUUID().toString()));
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
assertThat(priceReferenceResolver.resolveChannelReference(priceBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve the channel reference on PriceDraft"
+ " with country:'DE' and value: 'EUR 10.00000'. Reason: Found a UUID in the id field. Expecting a key"
+ " without a UUID value. If you want to allow UUID values for reference keys, please"
+ " use the allowUuidKeys(true) option in the sync options.");
}
示例8: createTestCartFromProduct
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
/**
* Creates a new cart and adds the passed product as a new line item using a random quantiy between 1 and 10.
*
* @param client the client handling the connection
* @return the created cart
*/
public static Cart createTestCartFromProduct(BlockingSphereClient client, Integer productNumber) throws ExecutionException, InterruptedException {
Address address = AddressBuilder.of(CountryCode.DE).firstName("FN").lastName("LN").streetName("sname").streetNumber("1").postalCode("12345").city("city").build();
List<LineItemDraft> lineItemDrafts = new ArrayList<>();
for (int i = 0; i < productNumber; i++) {
ProductProjection product = getProduct(client, Long.valueOf(i));
LineItemDraft lineItemDraft = LineItemDraft.of(product, product.getMasterVariant().getId(), new Random().nextInt(10) + 1);
lineItemDrafts.add(lineItemDraft);
}
CartDraft cartDraft = CartDraftBuilder.of(DefaultCurrencyUnits.EUR)
.country(CountryCode.DE)
.locale(Locale.GERMAN)
.lineItems(lineItemDrafts)
.billingAddress(address).shippingAddress(address)
.build();
return client.executeBlocking(CartCreateCommand.of(cartDraft));
}
开发者ID:commercetools,项目名称:commercetools-payment-integration-java,代码行数:26,代码来源:IntegrationTestUtils.java
示例9: getResource
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
private Response getResource(String code)
{
// Look up a CountryCode instance that has the ISO 3166-1 code.
CountryCode cc = lookup(code);
Map<String, Object> data = new LinkedHashMap<String, Object>();
if (cc != null)
{
// Pack the data into a Map.
data.put("name", cc.getName());
data.put("alpha2", cc.getAlpha2());
data.put("alpha3", cc.getAlpha3());
data.put("numeric", cc.getNumeric());
data.put("currency", cc.getCurrency());
}
// Convert the data to JSON.
String json = GSON.toJson(data);
// Create a response of "200 OK".
return Response.ok(json, "application/json;charset=UTF-8").build();
}
示例10: createProductWithSkus
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
public static Product createProductWithSkus(final BlockingSphereClient sphereClient, Set<String> skus) {
PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("123456"), "EUR")).withCountry(CountryCode.DE);
List<ProductVariantDraft> productVariantDrafts = skus.stream().map(sku -> ProductVariantDraftBuilder.of().sku(sku).build()).collect(Collectors.toList());
final ProductType productType = createProductType(sphereClient);
final ProductDraftBuilder productDraftBuilder = ProductDraftBuilder.of(productType, LocalizedString.of(Locale.ENGLISH, "product-name"),
LocalizedString.of(Locale.ENGLISH, RandomStringUtils.randomAlphabetic(10)), productVariantDrafts);
final Product product = sphereClient.executeBlocking(ProductCreateCommand.of(productDraftBuilder.publish(true).build()));
final AddPrice addPrice = AddPrice.of(product.getMasterData().getCurrent().getMasterVariant().getId(), priceDraft);
Product productWithPrice = sphereClient.executeBlocking(ProductUpdateCommand.of(product, asList(addPrice, Publish.of())));
return productWithPrice;
}
开发者ID:commercetools,项目名称:commercetools-sunrise-data,代码行数:13,代码来源:OrdersImportJobConfigurationIntegrationTest.java
示例11: shippingAddress
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Override
public Address shippingAddress() {
final CountryCode country = CountryCode.getByCode(countryShipping);
return AddressBuilder.of(country)
.title(titleShipping)
.firstName(firstNameShipping)
.lastName(lastNameShipping)
.streetName(streetNameShipping)
.additionalStreetInfo(additionalStreetInfoShipping)
.city(cityShipping)
.postalCode(postalCodeShipping)
.region(regionShipping)
.phone(phoneShipping)
.email(emailShipping)
.build();
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:17,代码来源:DefaultCheckoutAddressFormData.java
示例12: billingAddress
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Override
@Nullable
public Address billingAddress() {
if (billingAddressDifferentToBillingAddress) {
final CountryCode country = CountryCode.getByCode(countryBilling);
return AddressBuilder.of(country)
.title(titleBilling)
.firstName(firstNameBilling)
.lastName(lastNameBilling)
.streetName(streetNameBilling)
.additionalStreetInfo(additionalStreetInfoBilling)
.city(cityBilling)
.postalCode(postalCodeBilling)
.region(regionBilling)
.phone(phoneBilling)
.email(emailBilling)
.build();
} else {
return null;
}
}
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:22,代码来源:DefaultCheckoutAddressFormData.java
示例13: createProjectContext
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
private static ProjectContext createProjectContext(final List<Locale> locales, final List<CountryCode> countries,
final List<CurrencyUnit> currencies) {
return new ProjectContext() {
@Override
public List<Locale> locales() {
return locales;
}
@Override
public List<CountryCode> countries() {
return countries;
}
@Override
public List<CurrencyUnit> currencies() {
return currencies;
}
};
}
示例14: setCountryCode
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
public void setCountryCode(String countryCode) throws InvalidCountryCode {
CountryCode cc = CountryCode.getByCode(countryCode);
if(cc == null) {
// There is a chance it came in as United States for example.
List<CountryCode> results = CountryCode.findByName(countryCode);
if(results.size() < 1 || results.size() > 1) {
throw new InvalidCountryCode("Invalid Country Code detected: " + countryCode);
}
cc = results.get(0);
}
if(cc.toString().length() != 2) {
throw new InvalidCountryCode("Invalid Country Code detected: " + countryCode);
}
this.countryCode = cc.toString();
}
示例15: resolveReferences_WithNoCustomTypeReferenceAndNoChannelReference_ShouldNotResolveReferences
import com.neovisionaries.i18n.CountryCode; //导入依赖的package包/类
@Test
public void resolveReferences_WithNoCustomTypeReferenceAndNoChannelReference_ShouldNotResolveReferences() {
final PriceDraft priceDraft = PriceDraftBuilder.of(MoneyImpl.of(BigDecimal.TEN, DefaultCurrencyUnits.EUR))
.country(CountryCode.DE)
.build();
final PriceReferenceResolver priceReferenceResolver =
new PriceReferenceResolver(syncOptions, typeService, channelService);
final PriceDraft referencesResolvedDraft = priceReferenceResolver.resolveReferences(priceDraft)
.toCompletableFuture().join();
assertThat(referencesResolvedDraft.getCustom()).isNull();
assertThat(referencesResolvedDraft.getChannel()).isNull();
}