@Override public long getVersion() { return delegate.getVersion(); }
@Override public Long getVersion() { return delegate.getVersion(); }
@Override public Long getVersion() { return delegate.getVersion(); }
@Override public long getVersion() { return delegate.getVersion(); }
@Override public long getVersion() { return delegate.getVersion(); }
@Override public Long getVersion() { return delegate.getVersion(); }
static String toString(final Category category) { return new ToStringBuilder(category, SdkDefaults.TO_STRING_STYLE) .append("id", category.getId()) .append("version", category.getVersion()) .append("createdAt", category.getCreatedAt()) .append("lastModifiedAt", category.getLastModifiedAt()) .append("name", category.getName()) .append("slug", category.getSlug()) .append("description", category.getDescription()) .append("ancestors", join(category.getAncestors())) .append("parent", category.getParent()) .append("orderHint", category.getOrderHint()) .toString(); }
public static String toString(final Category category) { final List<String> pathInTreeIds = category.getPathInTree().stream().map(Category::getId).collect(toList()); return new ToStringBuilder(category, Base.TO_STRING_STYLE). append("id", category.getId()). append("version", category.getVersion()). append("createdAt", category.getCreatedAt()). append("lastModifiedAt", category.getLastModifiedAt()). append("name", category.getName()). append("slug", category.getSlug()). append("description", category.getDescription()). append("ancestors", join(category.getAncestors())). append("parent", category.getParent()). append("orderHint", category.getOrderHint()). append("children", category.getChildren()). append("pathInTree", join(pathInTreeIds)).toString(); } }
public static String toString(final Category category) { final List<String> pathInTreeIds = category.getPathInTree().stream().map(Category::getId).collect(toList()); return new ToStringBuilder(category). append("id", category.getId()). append("version", category.getVersion()). append("createdAt", category.getCreatedAt()). append("lastModifiedAt", category.getLastModifiedAt()). append("name", category.getName()). append("slug", category.getSlug()). append("description", category.getDescription()). append("ancestors", join(category.getAncestors())). append("parent", category.getParent()). append("orderHint", category.getOrderHint()). append("children", category.getChildren()). append("pathInTree", join(pathInTreeIds)).toString(); } }
public static String toString(final Category category) { final List<String> pathInTreeIds = category.getPathInTree().stream().map(Category::getId).collect(toList()); return new ToStringBuilder(category). append("id", category.getId()). append("version", category.getVersion()). append("createdAt", category.getCreatedAt()). append("lastModifiedAt", category.getLastModifiedAt()). append("name", category.getName()). append("slug", category.getSlug()). append("description", category.getDescription()). append("ancestors", join(category.getAncestors())). append("parent", category.getParent()). append("orderHint", category.getOrderHint()). append("children", category.getChildren()). append("pathInTree", join(pathInTreeIds)).toString(); } }
@Test public void execution() throws Exception { withCategory(client(), category -> { final ObjectMapper objectMapper = SphereJsonUtils.newObjectMapper(); final ObjectNode body = objectMapper.createObjectNode(); body.put("version", category.getVersion()); final ArrayNode actions = body.putArray("actions"); final ObjectNode changeNameUpdateAction = objectMapper.createObjectNode(); final String newName = "New Name"; changeNameUpdateAction.put("action", "changeName").set("name", objectMapper.createObjectNode().put("en", newName)); actions.add(changeNameUpdateAction); final JsonNode jsonNode = client().executeBlocking(JsonNodeSphereRequest.of(POST, "/categories/" + category.getId(), body)); assertThat(jsonNode.get("name").get("en").asText()).isEqualTo(newName); }); }
@Test public void retryDelete() throws InterruptedException { final SphereClient client = getSphereClient(getDeleteHttpClient()); final SphereClient retryClient = RetryDeleteExample.ofRetry(client); final Category result = blockingWait(retryClient.execute(CategoryDeleteCommand.of(Versioned.of("some-id", 5L))), 800, TimeUnit.MILLISECONDS);//thread pool needs warm-up Assertions.assertThat(result.getVersion()).isEqualTo(7L); }
@Test public void updateCommandDsl() throws Exception { withCategory(client(), category -> { final LocalizedString newName = LocalizedString.ofEnglish("new name"); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, singletonList(ChangeName.of(newName))); final Category updatedCategory = client().executeBlocking(command); assertThat(updatedCategory.getName()).isEqualTo(newName); final LocalizedString newName2 = LocalizedString.ofEnglish("new name2"); final CategoryUpdateCommand command2 = CategoryUpdateCommand.of(category /** with old version */, singletonList(ChangeName.of(newName2))); final Category againUpdatedCategory = client().executeBlocking(command2.withVersion(updatedCategory)); assertThat(againUpdatedCategory.getName()).isEqualTo(newName2); assertThat(againUpdatedCategory.getVersion()).isGreaterThan(updatedCategory.getVersion()); }); }
@Test public void concurrentModification() throws Exception { withCategory(client(), cat -> { final CategoryUpdateCommand cmd = CategoryUpdateCommand.of(cat, ChangeName.of(LocalizedString.ofEnglish("new"))); final Category successfulUpdatedCategory = client().executeBlocking(cmd); final Throwable throwable = catchThrowable(() -> client().executeBlocking(cmd));//same command twice assertThat(throwable).isInstanceOf(ConcurrentModificationException.class); final ConcurrentModificationException exception = (ConcurrentModificationException) throwable; assertThat(exception.getCurrentVersion()) .isGreaterThanOrEqualTo(successfulUpdatedCategory.getVersion()); }); }
@Test public void referenceExpansionForDeletionByKey() throws Exception { final String key = randomKey(); final Category parent = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).build())); final Category category = client().executeBlocking(CategoryCreateCommand.of(CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).key(key).parent(parent).build())); final CategoryDeleteCommand deleteCommand = CategoryDeleteCommand.ofKey(key, category.getVersion()).plusExpansionPaths(m -> m.parent()); final Category deletedCategory = client().executeBlocking(deleteCommand); assertThat(deletedCategory.getParent().getObj()).isNotNull().isEqualTo(parent); client().executeBlocking(CategoryDeleteCommand.of(parent)); } }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()). orderHint(category.getOrderHint()).children(category.getChildren()). pathInTree(category.getPathInTree()); }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()). orderHint(category.getOrderHint()).externalId(category.getExternalId()).children(category.getChildren()). pathInTree(category.getPathInTree()); }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()). orderHint(category.getOrderHint()).externalId(category.getExternalId()).children(category.getChildren()). pathInTree(category.getPathInTree()); }
@Test public void executionForDeletionByKey() throws Exception { final String key = randomKey(); final CategoryDraft draft = CategoryDraftBuilder.of(randomLocalizedString(), randomSlug()).key(key).build(); final Category category = client().executeBlocking(CategoryCreateCommand.of(draft)); client().executeBlocking(CategoryDeleteCommand.ofKey(key,category.getVersion())); assertThat(client().executeBlocking(CategoryQuery.of().byId(category.getId())).head()).isEmpty(); }
public static CategoryBuilder of(final Category category) { return new CategoryBuilder(category.getId(), category.getName(), category.getSlug()). version(category.getVersion()).createdAt(category.getCreatedAt()). lastModifiedAt(category.getLastModifiedAt()). name(category.getName()).slug(category.getSlug()).description(category.getDescription()). ancestors(category.getAncestors()).parent(category.getParent()).assets(category.getAssets()). orderHint(category.getOrderHint()).externalId(category.getExternalId()); }