当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject.getJsonObject方法代码示例

本文整理汇总了Java中io.vertx.core.json.JsonObject.getJsonObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.getJsonObject方法的具体用法?Java JsonObject.getJsonObject怎么用?Java JsonObject.getJsonObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.json.JsonObject的用法示例。

在下文中一共展示了JsonObject.getJsonObject方法的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: processOneResult

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
protected void processOneResult(final JsonObject dataChange) {

		final JsonObject data = dataChange.getJsonObject("data");
		final JsonObject payload = data.getJsonObject("payload");
		// We send it off to the eventbus and in any case have the
		// final destination header set - just in case
		final EventBus eb = this.getVertx().eventBus();
		final DeliveryOptions opts = new DeliveryOptions();
		this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
			opts.addHeader(Constants.BUS_FINAL_DESTINATION, destination);
		});

		// Intermediate step for deduplication of messages
		if (this.useDedupService()) {
			eb.publish(this.getListenerConfig().getEventBusDedupAddress(), payload, opts);
		} else {
			this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
				try {
					eb.publish(destination, payload, opts);
					this.logger.info("Sending to [" + destination + "]:" + payload.toString());
				} catch (final Throwable t) {
					this.logger.error(t.getMessage(), t);
				}
			});
		}
	}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:27,代码来源:CometD.java


示例2: createFromJSON

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
public static Message createFromJSON (JsonObject json) {
    Message message = new Message();

    //get header information
    message.event = json.getString("event");
    String messageID = json.getString("messageID");
    int statusCode = json.getInteger("statusCode");
    message.type = ResponseType.getByString(json.getString("status"));
    message.data = json.getJsonObject("data");
    message.ssid = json.getString("ssid");

    if (!messageID.isEmpty() && !messageID.equals("none")) {
        //get UUID
        message.uuid = UUID.fromString(messageID);
    }

    return message;
}
 
开发者ID:open-erp-systems,项目名称:erp-frontend,代码行数:19,代码来源:Message.java


示例3: processOneResult

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
/**
 * @see net.wissel.salesforce.vertx.listener.CometD#processOneResult(io.vertx.core.json.JsonObject)
 */
@Override
protected void processOneResult(JsonObject dataChange) {
	final JsonObject data = dataChange.getJsonObject("data");
	final JsonObject payload = data.getJsonObject("payload");
	final String objectType = payload.getString("ObjectType__c");
	// We send it off to the eventbus
	final EventBus eb = this.getVertx().eventBus();
	this.getListenerConfig().getEventBusAddresses().forEach(destination -> {
		try {
			eb.publish(destination+objectType, payload);
			this.logger.info("Sending to [" + destination+objectType + "]:" + payload.toString());
		} catch (final Throwable t) {
			this.logger.error(t.getMessage(), t);
		}
	});
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:20,代码来源:CometDChangeObject.java


示例4: configureBridgeOptions

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
private BridgeOptions configureBridgeOptions(JsonObject config) {
    BridgeOptions bridgeOptions = new BridgeOptions();
    JsonObject addresses=config.getJsonObject(ADDRESSES);

    JsonArray outbounds=addresses.getJsonArray(OUTBOUND);
    JsonArray inbounds=addresses.getJsonArray(INBOUND);

    outbounds.forEach(o-> addOutboundPermitted(bridgeOptions, (JsonObject) o));
    inbounds.forEach(i-> addInboundPermitted(bridgeOptions, (JsonObject) i));
    return bridgeOptions;
}
 
开发者ID:GwtDomino,项目名称:domino-event-bus,代码行数:12,代码来源:VertxConfigSockJsConfigurator.java


示例5: getResolver

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
private Resolver<T> getResolver(final RoutingContext context,
                                final Epsilon<T> income) {
    /** 1.Read the resolver first **/
    final Annotation annotation = income.getAnnotation();
    final Class<?> resolverCls = Instance.invoke(annotation, "resolver");
    /** 2.Check configured in default **/
    if (null == resolverCls) {
        /** 3. Old path **/
        final JsonObject content = NODE.read();
        final String header = context.request().getHeader(HttpHeaders.CONTENT_TYPE);
        final String resolver;
        if (null == header) {
            resolver = content.getString("default");
        } else {
            final MediaType type = MediaType.valueOf(header);
            final JsonObject resolverMap = content.getJsonObject(type.getType());
            resolver = resolverMap.getString(type.getSubtype());
        }
        LOGGER.info(Info.RESOLVER, resolver, header, context.request().absoluteURI());
        return Instance.singleton(resolver);
    } else {
        LOGGER.info(Info.RESOLVER_CONFIG, resolverCls);
        return Instance.singleton(resolverCls);
    }
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:26,代码来源:MimeAtomic.java


示例6: visit

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Override
public ConcurrentMap<String, VertxOptions> visit(final String... keys)
        throws ZeroException {
    // 1. Must be the first line, fixed position.
    Ensurer.eqLength(getClass(), 0, (Object[]) keys);
    // 2. Visit the node for vertx
    final JsonObject data = this.NODE.read();
    // 3. Vertx node validation.
    final JsonObject vertxData = data.getJsonObject(KEY);
    LOGGER.info(Info.INF_B_VERIFY, KEY, getClass().getSimpleName(), vertxData);
    Fn.shuntZero(() -> Ruler.verify(KEY, vertxData), vertxData);
    // 4. Set cluster options
    this.clusterOptions = this.clusterTransformer.transform(data.getJsonObject(YKEY_CLUSTERED));
    // 5. Transfer Data
    return visit(vertxData.getJsonArray(YKEY_INSTANCE));
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:VertxVisitor.java


示例7: searchAnnotations

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
/**
 * Searches for annotation in the given time range
 *
 * @param msg
 */
private void searchAnnotations(final Message<JsonObject> msg) {

    final JsonObject annotation = msg.body();
    LOG.debug("{}\n{}",address, annotation.encodePrettily());

    //get the parameter from the request
    final String from = annotation.getJsonObject("range").getString("from");
    final String to = annotation.getJsonObject("range").getString("to");
    final Range range = rangeParser.parse(from, to);
    final JsonObject an = annotation.getJsonObject("annotation");

    //build the query and find options
    final JsonObject annotationQuery = $and(obj(an.getString("query")),
                                            obj("n.begin", $gte(range.getStart())),
                                            obj("n.begin", $lte(range.getEnd())));
    final FindOptions findOptions = new FindOptions().setSort(obj("n.begin", 1)).setLimit(1);

    //query for annotations and map the result
    client.findWithOptions(collectionName, annotationQuery, findOptions, result -> {
        if (result.succeeded()) {
            msg.reply(result.result()
                            .stream()
                            .map(a -> obj().put("annotation", an)
                                           .put("time", a.getJsonObject("n").getLong("begin"))
                                           .put("title", a.getJsonObject("t").getString("name"))
                                           .put("tags", arr()))
                            .collect(toJsonArray()));
        } else {
            LOG.error("Annotation query failed", result.cause());
            msg.reply(arr());
        }
    });
}
 
开发者ID:gmuecke,项目名称:grafana-vertx-datasource,代码行数:39,代码来源:AnnotationVerticle.java


示例8: getClearJson

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
/**
 * 解析支付宝授权后的响应对象,获取对应简洁的JSON
 *
 * @param res 支付宝授权后的响应对象
 * @return 简洁的JSON,不包含签名及重复的一些字段
 *
 * @author Leibniz.Hu
 */
private JsonObject getClearJson(AlipayResponse res) {
    JsonObject bodyJson = new JsonObject(res.getBody());
    if (bodyJson.containsKey("alipay_user_info_share_response")) {
        return bodyJson.getJsonObject("alipay_user_info_share_response");
    } else if (bodyJson.containsKey("alipay_system_oauth_token_response")) {
        return bodyJson.getJsonObject("alipay_system_oauth_token_response");
    } else {
        return bodyJson;
    }
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:19,代码来源:AlipayOauthSubRouter.java


示例9: build

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
private static Envelop build(final JsonObject json) {
    Envelop envelop = Envelop.ok();
    // 1. Headers
    if (null != json) {
        // 2.Rebuild
        if (json.containsKey("data")) {
            envelop = Envelop.success(json.getValue("data"));
        }
        // 3.Header
        if (null != json.getValue("header")) {
            final MultiMap headers = MultiMap.caseInsensitiveMultiMap();
            final JsonObject headerData = json.getJsonObject("header");
            for (final String key : headerData.fieldNames()) {
                final Object value = headerData.getValue(key);
                if (null != value) {
                    headers.set(key, value.toString());
                }
            }
            envelop.setHeaders(headers);
        }
        // 4.User
        if (null != json.getValue("user")) {
            envelop.setUser(new VirtualUser(json.getJsonObject("user")));
        }
    }
    return envelop;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:28,代码来源:DataEncap.java


示例10: verify

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
/**
 * @param wallClses
 * @param keysRef
 * @return
 */
private JsonObject verify(final Set<Class<?>> wallClses,
                          final ConcurrentMap<String, Class<?>> keysRef) {
    /** Wall duplicated **/
    final Set<String> hashs = new HashSet<>();
    Observable.fromIterable(wallClses)
            .filter(Objects::nonNull)
            .map(item -> {
                final Annotation annotation = item.getAnnotation(Wall.class);
                // Add configuration key into keys;
                keysRef.put(Instance.invoke(annotation, "value"), item);
                return this.hashPath(annotation);
            }).subscribe(hashs::add);
    
    // Duplicated adding.
    Fn.flingUp(hashs.size() != wallClses.size(), LOGGER,
            WallDuplicatedException.class, getClass(),
            wallClses.stream().map(Class::getName).collect(Collectors.toSet()));

    /** Shared key does not existing **/
    final JsonObject config = NODE.read();
    Fn.flingUp(!config.containsKey(KEY), LOGGER,
            DynamicKeyMissingException.class, getClass(),
            KEY, config);

    /** Wall key missing **/
    final JsonObject hitted = config.getJsonObject(KEY);
    for (final String key : keysRef.keySet()) {
        Fn.flingUp(null == hitted || !hitted.containsKey(key), LOGGER,
                WallKeyMissingException.class, getClass(),
                key, keysRef.get(key));
    }
    return hitted;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:39,代码来源:WallInquirer.java


示例11: createRecord

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
private Record createRecord(final JsonObject item) {
    final String name = item.getString(NAME);
    final String host = item.getString(HOST);
    final Integer port = item.getInteger(PORT);
    final JsonObject meta = item.getJsonObject(META);
    return HttpEndpoint.createRecord(
            name, host, port, "/*", meta
    );
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:10,代码来源:EndPointOrigin.java


示例12: init

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
private void init(final JsonObject raw) {
    // Options
    initOpts(raw);
    // Config
    this.endpoint = raw.getString("endpoint");
    if (raw.containsKey("config")) {
        this.config = raw.getJsonObject("config");
    } else {
        this.config = new JsonObject();
    }
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:12,代码来源:FeignDepot.java


示例13: init

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
static <R> R init(final String key,
                  final Function<JsonObject, R> executor,
                  final Class<?> clazz) {
    final Node<JsonObject> node = Instance.instance(ZeroUniform.class);
    final JsonObject options = node.read();
    final Annal logger = Annal.get(clazz);
    Fn.flingUp(null == options || !options.containsKey(key)
            , logger, ConfigKeyMissingException.class,
            clazz, key);
    final JsonObject config = options.getJsonObject(key);
    Fn.flingUp(() -> Ruler.verify(key, config), logger);
    return executor.apply(config);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:14,代码来源:Infix.java


示例14: transform

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Override
public HttpServerOptions transform(final JsonObject input) {
    final JsonObject config = input.getJsonObject(ServerVisitor.YKEY_CONFIG, null);
    return Fn.getSemi(null == config, LOGGER,
            HttpServerOptions::new,
            () -> new HttpServerOptions(config));
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:8,代码来源:HttpServerStrada.java


示例15: transform

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Override
public VertxOptions transform(final JsonObject input) {
    final JsonObject config = input.getJsonObject(NodeVisitor.YKEY_OPTIONS, null);
    return Fn.getSemi(null == config, LOGGER,
            VertxOptions::new,
            () -> new VertxOptions(config));
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:8,代码来源:VertxStrada.java


示例16: createdRequestHasCreationMetadata

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Test
public void createdRequestHasCreationMetadata()
  throws InterruptedException,
  MalformedURLException,
  TimeoutException,
  ExecutionException {

  CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();

  String creatorId = UUID.randomUUID().toString();

  DateTime requestMade = DateTime.now();

  client.post(requestStorageUrl(),
    new RequestRequestBuilder().create(), StorageTestSuite.TENANT_ID,
    creatorId, ResponseHandler.json(createCompleted));

  JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to create loan policy: %s", postResponse.getBody()),
    postResponse.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));

  JsonResponse response = postResponse;

  JsonObject createdRequest = response.getJson();

  assertThat("Request should have metadata property",
    createdRequest.containsKey(METADATA_PROPERTY), is(true));

  JsonObject metadata = createdRequest.getJsonObject(METADATA_PROPERTY);

  assertThat("Request should have created user",
    metadata.getString("createdByUserId"), is(creatorId));

  assertThat("Request should have created date close to when request was made",
    metadata.getString("createdDate"),
    is(withinSecondsAfter(Seconds.seconds(2), requestMade)));

  //RAML-Module-Builder also populates updated information at creation time
  assertThat("Request should have updated user",
    metadata.getString("updatedByUserId"), is(creatorId));

  assertThat("Request should have update date close to when request was made",
    metadata.getString("updatedDate"),
    is(withinSecondsAfter(Seconds.seconds(2), requestMade)));
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:47,代码来源:RequestsApiTest.java


示例17: updatedRequestHasUpdatedMetadata

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Test
public void updatedRequestHasUpdatedMetadata()
  throws InterruptedException,
  MalformedURLException,
  TimeoutException,
  ExecutionException,
  UnsupportedEncodingException {

  UUID id = UUID.randomUUID();

  JsonObject request = new RequestRequestBuilder().withId(id).create();

  JsonResponse createResponse = createRequest(request);

  JsonObject createdMetadata = createResponse.getJson()
    .getJsonObject(METADATA_PROPERTY);

  CompletableFuture<TextResponse> updateCompleted = new CompletableFuture<>();

  String updaterId = UUID.randomUUID().toString();

  DateTime requestMade = DateTime.now();

  client.put(requestStorageUrl(String.format("/%s", id)),
    request, StorageTestSuite.TENANT_ID, updaterId,
    ResponseHandler.text(updateCompleted));

  TextResponse response = updateCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to update request: %s", response.getBody()),
    response.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));

  JsonResponse getAfterUpdateResponse = getById(id);

  JsonObject updatedRequest = getAfterUpdateResponse.getJson();

  assertThat("Request should have metadata property",
    updatedRequest.containsKey(METADATA_PROPERTY), is(true));

  JsonObject metadata = updatedRequest.getJsonObject(METADATA_PROPERTY);

  assertThat("Request should have same created user",
    metadata.getString("createdByUserId"),
    is(createdMetadata.getString("createdByUserId")));

  assertThat("Request should have same created date",
    metadata.getString("createdDate"),
    is(createdMetadata.getString("createdDate")));

  assertThat("Request should have updated user",
    metadata.getString("updatedByUserId"), is(updaterId));

  assertThat("Request should have updated date close to when request was made",
    metadata.getString("updatedDate"),
    is(withinSecondsAfter(Seconds.seconds(2), requestMade)));

  assertThat("Request should have updated date different to original updated date",
    metadata.getString("updatedDate"), is(not(createdMetadata.getString("updatedDate"))));
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:60,代码来源:RequestsApiTest.java


示例18: canCreateALoanPolicy

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Test
public void canCreateALoanPolicy()
  throws InterruptedException,
  MalformedURLException,
  TimeoutException,
  ExecutionException,
  UnsupportedEncodingException {

  CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();

  UUID id = UUID.randomUUID();

  JsonObject loanPolicyRequest = new LoanPolicyRequestBuilder()
    .withId(id)
    .withName("Example Loan Policy")
    .withDescription("An example loan policy")
    .create();

  client.post(loanPolicyStorageUrl(),
    loanPolicyRequest, StorageTestSuite.TENANT_ID,
    ResponseHandler.json(createCompleted));

  JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to create loan policy: %s", response.getBody()),
    response.getStatusCode(), is(HttpURLConnection.HTTP_CREATED));

  JsonObject representation = response.getJson();

  assertThat(representation.getString("id"), is(id.toString()));
  assertThat(representation.getString("name"), is("Example Loan Policy"));
  assertThat(representation.getString("description"), is("An example loan policy"));
  assertThat(representation.getBoolean("loanable"), is(true));
  assertThat(representation.getBoolean("renewable"), is(true));

  assertThat(representation.containsKey("loansPolicy"), is(true));

  JsonObject loansPolicy = representation.getJsonObject("loansPolicy");

  assertThat(loansPolicy.getString("profileId"), is("ROLLING"));
  assertThat(loansPolicy.getJsonObject("period"), matchesPeriod(1, "MONTH"));
  assertThat(loansPolicy.getString("closedLibraryDueDateManagementId"), is("KEEP_CURRENT_DATE"));
  assertThat(loansPolicy.getJsonObject("existingRequestsPeriod"), matchesPeriod(1, "WEEK"));
  assertThat(loansPolicy.getJsonObject("gracePeriod"), matchesPeriod(7, "DAYS"));

  assertThat(representation.containsKey("renewalsPolicy"), is(true));

  JsonObject renewalsPolicy = representation.getJsonObject("renewalsPolicy");

  assertThat(renewalsPolicy.getBoolean("unlimited"), is(true));
  assertThat(renewalsPolicy.getString("renewFromId"), is("CURRENT_DUE_DATE"));
  assertThat(renewalsPolicy.getBoolean("differentPeriod"), is(true));
  assertThat(renewalsPolicy.getJsonObject("period"), matchesPeriod(30, "DAYS"));
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:55,代码来源:LoanPoliciesApiTest.java


示例19: canCreateALoanPolicyAtASpecificLocation

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Test
public void canCreateALoanPolicyAtASpecificLocation()
  throws InterruptedException,
  MalformedURLException,
  TimeoutException,
  ExecutionException,
  UnsupportedEncodingException {

  CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();

  UUID id = UUID.randomUUID();

  JsonObject loanPolicyRequest = new LoanPolicyRequestBuilder()
    .withId(id)
    .create();

  client.put(loanPolicyStorageUrl(String.format("/%s", id.toString())),
    loanPolicyRequest, StorageTestSuite.TENANT_ID,
    ResponseHandler.json(createCompleted));

  JsonResponse createResponse = createCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to create loan policy: %s", createResponse.getBody()),
    createResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));

  CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();

  client.get(loanPolicyStorageUrl(String.format("/%s", id.toString())),
    StorageTestSuite.TENANT_ID,
    ResponseHandler.json(getCompleted));

  JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to get updated loan policy: %s", getResponse.getBody()),
    getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));

  JsonObject representation = getResponse.getJson();

  assertThat(representation.getString("id"), is(id.toString()));
  assertThat(representation.getString("description"), is("An example loan policy"));
  assertThat(representation.getString("name"), is("Example Loan Policy"));
  assertThat(representation.getBoolean("loanable"), is(true));
  assertThat(representation.getBoolean("renewable"), is(true));

  assertThat(representation.containsKey("loansPolicy"), is(true));

  JsonObject loansPolicy = representation.getJsonObject("loansPolicy");

  assertThat(loansPolicy.getString("profileId"), is("ROLLING"));
  assertThat(loansPolicy.getJsonObject("period"), matchesPeriod(1, "MONTH"));
  assertThat(loansPolicy.getString("closedLibraryDueDateManagementId"), is("KEEP_CURRENT_DATE"));
  assertThat(loansPolicy.getJsonObject("existingRequestsPeriod"), matchesPeriod(1, "WEEK"));
  assertThat(loansPolicy.getJsonObject("gracePeriod"), matchesPeriod(7, "DAYS"));

  assertThat(representation.containsKey("renewalsPolicy"), is(true));

  JsonObject renewalsPolicy = representation.getJsonObject("renewalsPolicy");

  assertThat(renewalsPolicy.getBoolean("unlimited"), is(true));
  assertThat(renewalsPolicy.getString("renewFromId"), is("CURRENT_DUE_DATE"));
  assertThat(renewalsPolicy.getBoolean("differentPeriod"), is(true));
  assertThat(renewalsPolicy.getJsonObject("period"), matchesPeriod(30, "DAYS"));
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:64,代码来源:LoanPoliciesApiTest.java


示例20: canUpdateAnExistingLoanPolicyByReplacingItsRepresentation

import io.vertx.core.json.JsonObject; //导入方法依赖的package包/类
@Test
  public void canUpdateAnExistingLoanPolicyByReplacingItsRepresentation()
  throws InterruptedException,
  MalformedURLException,
  TimeoutException,
  ExecutionException,
  UnsupportedEncodingException {

  UUID id = UUID.randomUUID();

  createLoanPolicy(new LoanPolicyRequestBuilder().withId(id).create());

  CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();

  JsonObject loanPolicyRequest = new LoanPolicyRequestBuilder()
    .withId(id)
    .withName("A Different Name")
    .withDescription("A different description")
    .create();

  client.put(loanPolicyStorageUrl(String.format("/%s", id.toString())),
    loanPolicyRequest, StorageTestSuite.TENANT_ID,
    ResponseHandler.json(updateCompleted));

  JsonResponse updateResponse = updateCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to update loan policy: %s", updateResponse.getBody()),
    updateResponse.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));

  CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();

  client.get(loanPolicyStorageUrl(String.format("/%s", id.toString())),
    StorageTestSuite.TENANT_ID,
    ResponseHandler.json(getCompleted));

  JsonResponse getResponse = getCompleted.get(5, TimeUnit.SECONDS);

  assertThat(String.format("Failed to get updated loan policy: %s", getResponse.getBody()),
    getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));

  JsonObject representation = getResponse.getJson();

  assertThat(representation.getString("id"), is(id.toString()));
  assertThat(representation.getString("name"), is("A Different Name"));
  assertThat(representation.getString("description"), is("A different description"));
  assertThat(representation.getBoolean("loanable"), is(true));
  assertThat(representation.getBoolean("renewable"), is(true));

  assertThat(representation.containsKey("loansPolicy"), is(true));

  JsonObject loansPolicy = representation.getJsonObject("loansPolicy");

  assertThat(loansPolicy.getString("profileId"), is("ROLLING"));
  assertThat(loansPolicy.getJsonObject("period"), matchesPeriod(1, "MONTH"));
  assertThat(loansPolicy.getString("closedLibraryDueDateManagementId"), is("KEEP_CURRENT_DATE"));
  assertThat(loansPolicy.getJsonObject("existingRequestsPeriod"), matchesPeriod(1, "WEEK"));
  assertThat(loansPolicy.getJsonObject("gracePeriod"), matchesPeriod(7, "DAYS"));

  assertThat(representation.containsKey("renewalsPolicy"), is(true));

  JsonObject renewalsPolicy = representation.getJsonObject("renewalsPolicy");

  assertThat(renewalsPolicy.getBoolean("unlimited"), is(true));
  assertThat(renewalsPolicy.getString("renewFromId"), is("CURRENT_DUE_DATE"));
  assertThat(renewalsPolicy.getBoolean("differentPeriod"), is(true));
  assertThat(renewalsPolicy.getJsonObject("period"), matchesPeriod(30, "DAYS"));
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:68,代码来源:LoanPoliciesApiTest.java



注:本文中的io.vertx.core.json.JsonObject.getJsonObject方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。