Java Code Examples for javax.ws.rs.core.Response.Status#getStatusCode()

The following examples show how to use javax.ws.rs.core.Response.Status#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void givenAValidCustomerIdWhenRetrievingACustomerThenReturnACustomer() throws JsonProcessingException {
	final ShopifyCustomer shopifyCustomer = buildShopifyCustomer();
	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append("customers").append(FORWARD_SLASH)
			.append(shopifyCustomer.getId()).toString();
	final ShopifyCustomerRoot shopifyCustomerRoot = new ShopifyCustomerRoot();
	shopifyCustomerRoot.setCustomer(shopifyCustomer);

	final String expectedResponseBodyString = getJsonString(ShopifyCustomerRoot.class, shopifyCustomerRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader("X-Shopify-Access-Token", accessToken).withMethod(Method.GET),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyCustomer actualCustomer = shopifySdk.getCustomer(shopifyCustomer.getId());

	assertCustomer(actualCustomer);
}
 
Example 2
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void givenSomeOrderIdWhenRetrievingOrderThenRetrieveOrder() throws JsonProcessingException {
	final ShopifyOrderRoot shopifyOrderRoot = new ShopifyOrderRoot();

	final ShopifyOrder shopifyOrder = new ShopifyOrder();
	shopifyOrder.setId("123");
	shopifyOrderRoot.setOrder(shopifyOrder);
	final String expectedImageResponseBodyString = getJsonString(ShopifyOrderRoot.class, shopifyOrderRoot);

	final String expectedImagePath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.VERSION_2020_01)
			.append(FORWARD_SLASH).append(ShopifySdk.ORDERS).append(FORWARD_SLASH).append("123").toString();

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedImagePath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withMethod(Method.GET),
			giveResponse(expectedImageResponseBodyString, MediaType.APPLICATION_JSON)
					.withStatus(expectedStatusCode));

	final ShopifyOrder actualShopifyOrder = shopifySdk.getOrder("123");
	assertEquals("123", actualShopifyOrder.getId());

}
 
Example 3
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 6 votes vote down vote up
@Test(expected = ShopifyErrorResponseException.class)
public void givenSomeInvalidStatusWhenUpdatingInventoryLevelThenExpectShopifyErrorResponseException()
		throws JsonProcessingException {
	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.INVENTORY_LEVELS)
			.append("/").append(ShopifySdk.SET).toString();
	final ShopifyInventoryLevelRoot shopifyInventoryLevelRoot = new ShopifyInventoryLevelRoot();
	final ShopifyInventoryLevel shopifyInventoryLevel = new ShopifyInventoryLevel();
	shopifyInventoryLevel.setAvailable(123L);
	shopifyInventoryLevel.setInventoryItemId("736472634");
	shopifyInventoryLevel.setLocationId("123123");
	shopifyInventoryLevelRoot.setInventoryLevel(shopifyInventoryLevel);

	final String expectedResponseBodyString = getJsonString(ShopifyInventoryLevelRoot.class,
			shopifyInventoryLevelRoot);

	final Status expectedStatus = Status.BAD_REQUEST;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withMethod(Method.POST),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	shopifySdk.updateInventoryLevel("123123", "736472634", 123L);
}
 
Example 4
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void givenSomeValidRequestWhenGettingProductCount() throws JsonProcessingException {
	final Count count = new Count();
	count.setCount(231);
	final String expectedResponseBodyString = getJsonString(Count.class, count);

	final String expectedImagePath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.PRODUCTS)
			.append(FORWARD_SLASH).append(ShopifySdk.COUNT).toString();

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedImagePath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withMethod(Method.GET),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final int actualProductCount = shopifySdk.getProductCount();
	assertEquals(231, actualProductCount);

}
 
Example 5
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void givenSomeValidAccessTokenAndSubdomainAndSomeValidRequestWheRevokingOauthTokenThenReturnTrue()
		throws Exception {

	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.OAUTH)
			.append(FORWARD_SLASH).append(ShopifySdk.REVOKE).toString();

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader("X-Shopify-Access-Token", accessToken).withMethod(Method.DELETE),
			giveResponse("", MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final boolean revokedOauthToken = shopifySdk.revokeOAuthToken();
	assertTrue(revokedOauthToken);

}
 
Example 6
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void givenSomeValidAccessTokenAndSubdomainAndValidRequestWhenRetrievingVariantMetafieldsThenReturnVariantMetafields()
		throws JsonProcessingException {

	final Metafield metafield = new Metafield();
	metafield.setKey("channelape_variant_id");
	metafield.setValue("8fb0fb40-ab18-439e-bc6e-394b63ff1819");
	metafield.setNamespace("channelape");
	metafield.setOwnerId("1234");
	metafield.setValueType(MetafieldValueType.STRING);
	metafield.setOwnerResource("variant");

	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.VARIANTS)
			.append("/1234/").append(ShopifySdk.METAFIELDS).toString();
	final MetafieldsRoot metafieldsRoot = new MetafieldsRoot();
	metafieldsRoot.setMetafields(Arrays.asList(metafield));

	final String expectedResponseBodyString = getJsonString(MetafieldsRoot.class, metafieldsRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();

	driver.addExpectation(
			onRequestTo(expectedPath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withMethod(Method.GET),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final List<Metafield> actualMetafields = shopifySdk.getVariantMetafields("1234");
	assertNotNull(actualMetafields);
	assertEquals(1, actualMetafields.size());
	assertEquals(metafield.getKey(), actualMetafields.get(0).getKey());
	assertEquals(metafield.getValue(), actualMetafields.get(0).getValue());
	assertEquals(metafield.getValueType(), actualMetafields.get(0).getValueType());
	assertEquals(metafield.getNamespace(), actualMetafields.get(0).getNamespace());
	assertEquals(metafield.getOwnerId(), actualMetafields.get(0).getOwnerId());
	assertEquals(metafield.getOwnerResource(), actualMetafields.get(0).getOwnerResource());
}
 
Example 7
Source File: ServerException.java    From proteus with Apache License 2.0 5 votes vote down vote up
/**
 * @param message
 */
public ServerException(String message, Status status)
{
    super(message);

    this.status = status.getStatusCode();
}
 
Example 8
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void givenShopWithNoOrdersAndSomeMininumCreationDateAndPage1And80PageSizeWhenRetrievingOrdersThenReturnNoOrders()
		throws JsonProcessingException {
	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.VERSION_2020_01)
			.append(FORWARD_SLASH).append(ShopifySdk.ORDERS).toString();

	final ShopifyOrdersRoot shopifyOrdersRoot = new ShopifyOrdersRoot();

	final String expectedResponseBodyString = getJsonString(ShopifyOrdersRoot.class, shopifyOrdersRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	final int pageSize = 80;
	final DateTime minimumCreationDateTime = SOME_DATE_TIME;
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withParam(ShopifySdk.STATUS_QUERY_PARAMETER, ShopifySdk.ANY_STATUSES)
					.withParam(ShopifySdk.LIMIT_QUERY_PARAMETER, pageSize)
					.withParam(ShopifySdk.CREATED_AT_MIN_QUERY_PARAMETER, minimumCreationDateTime.toString())
					.withMethod(Method.GET),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyPage<ShopifyOrder> actualShopifyOrdersPage = shopifySdk.getOrders(minimumCreationDateTime,
			pageSize);

	assertEquals(0, actualShopifyOrdersPage.size());
}
 
Example 9
Source File: BaseResponseHandler.java    From agrest with Apache License 2.0 5 votes vote down vote up
private String buildErrorMessage(Status status, Response response) {

        String errorMessage = "Server returned " + status.getStatusCode() +
                    " (" + status.getReasonPhrase() + ")";

        String serverMessage = readMessage(response);
        if (serverMessage != null) {
            errorMessage += ". Message: " + serverMessage;
        }

        return errorMessage;
    }
 
Example 10
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void givenAValidQueryWhenRetrievingCustomersThenRetrieveJustThoseCustomersViaTheSearchAPI()
		throws JsonProcessingException {
	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.VERSION_2020_01)
			.append(FORWARD_SLASH).append("customers").append(FORWARD_SLASH).append("search").toString();
	final ShopifyCustomer shopifyCustomer = buildShopifyCustomer();
	final List<ShopifyCustomer> shopifyCustomers = new LinkedList<>();
	shopifyCustomers.add(shopifyCustomer);
	final ShopifyCustomersRoot shopifyCustomersRoot = new ShopifyCustomersRoot();
	shopifyCustomersRoot.setCustomers(shopifyCustomers);
	final String expectedResponseBodyString = getJsonString(ShopifyCustomersRoot.class, shopifyCustomersRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();

	final String query = "Austin";

	driver.addExpectation(
			onRequestTo(expectedPath).withHeader("X-Shopify-Access-Token", accessToken).withMethod(Method.GET)
					.withParam(ShopifySdk.LIMIT_QUERY_PARAMETER, 50)
					.withParam(ShopifySdk.QUERY_QUERY_PARAMETER, query),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyPage<ShopifyCustomer> actualCustomersPage = shopifySdk.searchCustomers(query);

	assertCustomers(actualCustomersPage);
}
 
Example 11
Source File: ServerException.java    From proteus with Apache License 2.0 5 votes vote down vote up
/**
 * @param cause
 */
public ServerException(Throwable cause, Status status)
{
    super(cause);

    this.status = status.getStatusCode();
}
 
Example 12
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void givenSomeValidAccessTokenAndSubdomainAndValidRequestWhenCreatingGiftCardThenCreateAndReturn()
		throws Exception {

	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.GIFT_CARDS).toString();
	final ShopifyGiftCardRoot shopifyGiftCardRoot = new ShopifyGiftCardRoot();
	final ShopifyGiftCard shopifyGiftCard = new ShopifyGiftCard();

	shopifyGiftCard.setInitialValue(new BigDecimal(41.21));
	shopifyGiftCard.setCode("ABCDEFGHIJKLMNOP");
	shopifyGiftCard.setBalance(new BigDecimal(41.21));
	final DateTime someDateTime = new DateTime();
	shopifyGiftCard.setExpiresOn(someDateTime);
	shopifyGiftCard.setCreatedAt(someDateTime);
	shopifyGiftCard.setCurrency("USD");
	shopifyGiftCard.setLastCharacters("MNOP");
	shopifyGiftCard.setId("1");
	shopifyGiftCard.setNote("Happy Birthday!");

	shopifyGiftCardRoot.setGiftCard(shopifyGiftCard);

	final String expectedResponseBodyString = getJsonString(ShopifyGiftCardRoot.class, shopifyGiftCardRoot);

	final Status expectedStatus = Status.CREATED;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	final JsonBodyCapture actualRequestBody = new JsonBodyCapture();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader("X-Shopify-Access-Token", accessToken).withMethod(Method.POST)
					.capturingBodyIn(actualRequestBody),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyGiftCardCreationRequest shopifyGiftCardCreationRequest = ShopifyGiftCardCreationRequest
			.newBuilder().withInitialValue(new BigDecimal(42.21)).withCode("ABCDEFGHIJKLMNOP").withCurrency("USD")
			.build();
	final ShopifyGiftCard actualShopifyGiftCard = shopifySdk.createGiftCard(shopifyGiftCardCreationRequest);

	assertEquals("ABCDEFGHIJKLMNOP", actualRequestBody.getContent().get("gift_card").get("code").asText());
	assertEquals("USD", actualRequestBody.getContent().get("gift_card").get("currency").asText());
	assertEquals(BigDecimal.valueOf(42.21),
			actualRequestBody.getContent().get("gift_card").get("initial_value").decimalValue());

	assertEquals(shopifyGiftCard.getId(), actualShopifyGiftCard.getId());
	assertEquals(shopifyGiftCard.getApiClientId(), actualShopifyGiftCard.getApiClientId());
	assertEquals(shopifyGiftCard.getInitialValue(), actualShopifyGiftCard.getInitialValue());
	assertEquals(0, shopifyGiftCard.getCreatedAt().compareTo(actualShopifyGiftCard.getCreatedAt()));
	assertEquals(shopifyGiftCard.getBalance(), actualShopifyGiftCard.getBalance());
	assertEquals(shopifyGiftCard.getCode(), actualShopifyGiftCard.getCode());
	assertEquals(0, shopifyGiftCard.getExpiresOn().compareTo(actualShopifyGiftCard.getExpiresOn()));
	assertNull(actualShopifyGiftCard.getDisabledAt());
	assertEquals(shopifyGiftCard.getLineItemId(), actualShopifyGiftCard.getLineItemId());
	assertEquals(shopifyGiftCard.getNote(), actualShopifyGiftCard.getNote());
	assertEquals(shopifyGiftCard.getLastCharacters(), actualShopifyGiftCard.getLastCharacters());
	assertEquals(shopifyGiftCard.getTemplateSuffix(), actualShopifyGiftCard.getTemplateSuffix());
	assertNull(actualShopifyGiftCard.getUpdatedAt());
}
 
Example 13
Source File: Diagnosis.java    From ldp4j with Apache License 2.0 4 votes vote down vote up
Diagnosis statusCode(Status status) {
	return new Diagnosis(status.getStatusCode(),this.diagnostic,this.mandatory);
}
 
Example 14
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void givenSomeValidAccessTokenAndSubdomainAndSomeProductMetafieldWhenCreatingProductMetafieldThenCreateAndProductMetafield()
		throws Exception {

	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.PRODUCTS)
			.append(FORWARD_SLASH).append("123").append(FORWARD_SLASH).append(ShopifySdk.METAFIELDS).toString();

	final Metafield metafield = new Metafield();
	metafield.setCreatedAt(new DateTime());
	metafield.setUpdatedAt(new DateTime());
	metafield.setValueType(MetafieldValueType.STRING);
	metafield.setId("123");
	metafield.setKey("channelape_product_id");
	metafield.setNamespace("channelape");
	metafield.setOwnerId("123");
	metafield.setOwnerResource("product");
	metafield.setValue("38728743");

	final MetafieldRoot metafieldRoot = new MetafieldRoot();
	metafieldRoot.setMetafield(metafield);

	final String expectedResponseBodyString = getJsonString(MetafieldRoot.class, metafieldRoot);

	final Status expectedStatus = Status.CREATED;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	final JsonBodyCapture actualRequestBody = new JsonBodyCapture();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader("X-Shopify-Access-Token", accessToken).withMethod(Method.POST)
					.capturingBodyIn(actualRequestBody),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyProductMetafieldCreationRequest shopifyProductMetafieldCreationRequest = ShopifyProductMetafieldCreationRequest
			.newBuilder().withProductId("123").withNamespace("channelape").withKey("channelape_product_id")
			.withValue("38728743").withValueType(MetafieldValueType.STRING).build();
	final Metafield actualMetafield = shopifySdk.createProductMetafield(shopifyProductMetafieldCreationRequest);

	assertEquals(shopifyProductMetafieldCreationRequest.getRequest().getKey().toString(),
			actualRequestBody.getContent().get("metafield").get("key").asText());
	assertEquals(shopifyProductMetafieldCreationRequest.getRequest().getValue(),
			actualRequestBody.getContent().get("metafield").get("value").asText());

	assertEquals(shopifyProductMetafieldCreationRequest.getRequest().getNamespace(),
			actualRequestBody.getContent().get("metafield").get("namespace").asText());
	assertEquals(shopifyProductMetafieldCreationRequest.getRequest().getValueType().toString(),
			actualRequestBody.getContent().get("metafield").get("value_type").asText());
	assertNotNull(actualMetafield);
	assertEquals(metafield.getId(), actualMetafield.getId());
	assertEquals(0, metafield.getCreatedAt().compareTo(actualMetafield.getCreatedAt()));
	assertEquals(metafield.getKey(), actualMetafield.getKey());
	assertEquals(metafield.getNamespace(), actualMetafield.getNamespace());
	assertEquals(metafield.getOwnerId(), actualMetafield.getOwnerId());
	assertEquals(metafield.getOwnerResource(), actualMetafield.getOwnerResource());
	assertEquals(0, metafield.getUpdatedAt().compareTo(actualMetafield.getUpdatedAt()));
	assertEquals(metafield.getValue(), actualMetafield.getValue());
	assertEquals(metafield.getValueType(), actualMetafield.getValueType());
}
 
Example 15
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void givenSomePageSizeWhenRetrievingOrdersThenRetrieveOrdersWithCorrectValues()
		throws JsonProcessingException {
	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.VERSION_2020_01)
			.append(FORWARD_SLASH).append(ShopifySdk.ORDERS).toString();

	final ShopifyOrdersRoot shopifyOrdersRoot = new ShopifyOrdersRoot();

	final ShopifyOrder shopifyOrder1 = new ShopifyOrder();
	shopifyOrder1.setId("someId");
	shopifyOrder1.setEmail("[email protected]");
	shopifyOrder1.setCustomer(SOME_CUSTOMER);

	final ShopifyLineItem shopifyLineItem1 = new ShopifyLineItem();
	shopifyLineItem1.setId("1234565");
	shopifyLineItem1.setSku("847289374");
	shopifyLineItem1.setName("Really Cool Product");
	shopifyOrder1.setLineItems(Arrays.asList(shopifyLineItem1));

	final ShopifyFulfillment shopifyFulfillment = new ShopifyFulfillment();
	shopifyFulfillment.setCreatedAt(SOME_DATE_TIME);
	shopifyFulfillment.setId("somelineitemid1");
	shopifyFulfillment.setLineItems(Arrays.asList(shopifyLineItem1));
	shopifyFulfillment.setTrackingUrl(null);
	shopifyFulfillment.setTrackingUrls(new LinkedList<>());
	shopifyOrder1.setFulfillments(Arrays.asList(shopifyFulfillment));
	shopifyOrdersRoot.setOrders(Arrays.asList(shopifyOrder1));

	final String expectedResponseBodyString = getJsonString(ShopifyOrdersRoot.class, shopifyOrdersRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withParam(ShopifySdk.STATUS_QUERY_PARAMETER, ShopifySdk.ANY_STATUSES)
					.withParam(ShopifySdk.LIMIT_QUERY_PARAMETER, 50).withMethod(Method.GET),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withHeader("Link",
					"<https://some-store.myshopify.com/admin/api/2019-10/orders?page_info=123>; rel=\"previous\", <https://humdingers-business-of-the-americas.myshopify.com/admin/api/2019-10/orders?page_info=456>; rel=\"next\"")
					.withStatus(expectedStatusCode));

	final ShopifyPage<ShopifyOrder> shopifyOrdersPage = shopifySdk.getOrders();

	final ShopifyOrder shopifyOrder = shopifyOrdersPage.get(0);
	assertEquals(shopifyOrder1.getId(), shopifyOrder.getId());
	assertEquals(shopifyOrder1.getEmail(), shopifyOrder.getEmail());
	assertEquals(shopifyOrder1.getFulfillments().get(0).getId(), shopifyOrder.getFulfillments().get(0).getId());
	assertTrue(shopifyOrder1.getFulfillments().get(0).getCreatedAt()
			.compareTo(shopifyOrder.getFulfillments().get(0).getCreatedAt()) == 0);
	assertEquals(shopifyOrder1.getFulfillments().get(0).getTrackingUrl(),
			shopifyOrder.getFulfillments().get(0).getTrackingUrl());
	assertEquals(shopifyOrder1.getFulfillments().get(0).getTrackingUrls(),
			shopifyOrder.getFulfillments().get(0).getTrackingUrls());
	assertEquals(shopifyOrder1.getFulfillments().get(0).getLineItems().get(0).getId(),
			shopifyOrder.getFulfillments().get(0).getLineItems().get(0).getId());
	assertEquals(shopifyOrder1.getFulfillments().get(0).getLineItems().get(0).getId(),
			shopifyOrder.getFulfillments().get(0).getLineItems().get(0).getId());
	assertEquals(shopifyOrder1.getFulfillments().get(0).getLineItems().get(0).getSku(),
			shopifyOrder.getFulfillments().get(0).getLineItems().get(0).getSku());
	assertEquals(shopifyOrder1.getFulfillments().get(0).getLineItems().get(0).getName(),
			shopifyOrder.getFulfillments().get(0).getLineItems().get(0).getName());

	assertEquals("456", shopifyOrdersPage.getNextPageInfo());
	assertEquals("123", shopifyOrdersPage.getPreviousPageInfo());
}
 
Example 16
Source File: SimpleClientResponse.java    From osiris with Apache License 2.0 4 votes vote down vote up
public void setStatus(Status status) {
	this.statusCode = status.getStatusCode();
}
 
Example 17
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void givenSomeUpdateCustomerRequestWhenUpdatingCustomerThenUpdateAndReturnCustomer()
		throws JsonProcessingException {
	final String someCustomerId = "some-id";
	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append("customers").append(FORWARD_SLASH)
			.append(someCustomerId).toString();
	final ShopifyCustomerUpdateRequest shopifyCustomerUpdateRequest = ShopifyCustomerUpdateRequest.newBuilder()
			.withId(someCustomerId).withFirstName("Ryan").withLastName("Kazokas")
			.withEmail("[email protected]").withPhone("57087482349").build();
	final ShopifyCustomerRoot shopifyCustomerRoot = new ShopifyCustomerRoot();
	final ShopifyCustomer shopifyCustomer = new ShopifyCustomer();
	shopifyCustomer.setFirstName("Ryan");
	shopifyCustomer.setLastname("Kazokas");
	shopifyCustomer.setEmail("[email protected]");
	shopifyCustomer.setNote("Some NOtes");
	shopifyCustomer.setOrdersCount(3);
	shopifyCustomer.setState("some-state");
	shopifyCustomer.setPhone("57087482349");
	shopifyCustomer.setTotalSpent(new BigDecimal(32.12));
	shopifyCustomerRoot.setCustomer(shopifyCustomer);
	final String expectedResponseBodyString = getJsonString(ShopifyCustomerRoot.class, shopifyCustomerRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	final JsonBodyCapture actualRequestBody = new JsonBodyCapture();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader("X-Shopify-Access-Token", accessToken).withMethod(Method.PUT)
					.capturingBodyIn(actualRequestBody),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyCustomer updatedCustomer = shopifySdk.updateCustomer(shopifyCustomerUpdateRequest);

	assertEquals("[email protected]", updatedCustomer.getEmail());
	assertEquals("Ryan", updatedCustomer.getFirstName());
	assertEquals("Kazokas", updatedCustomer.getLastname());
	assertEquals("Some NOtes", updatedCustomer.getNote());
	assertEquals(3, updatedCustomer.getOrdersCount());
	assertEquals("57087482349", updatedCustomer.getPhone());
	assertEquals("some-state", updatedCustomer.getState());
	assertEquals(new BigDecimal(32.12), updatedCustomer.getTotalSpent());

	assertEquals("[email protected]", actualRequestBody.getContent().get("customer").get("email").asText());
	assertEquals("Ryan", actualRequestBody.getContent().get("customer").get("first_name").asText());
	assertEquals("Kazokas", actualRequestBody.getContent().get("customer").get("last_name").asText());
	assertEquals("57087482349", actualRequestBody.getContent().get("customer").get("phone").asText());
}
 
Example 18
Source File: ShopifySdkTest.java    From shopify-sdk with Apache License 2.0 4 votes vote down vote up
@Test
public void givenSomeValidAccessTokenAndSubdomainAndVariantIdWhenGettinVariantThenGetVariant()
		throws JsonProcessingException {

	final ShopifyVariantRoot shopifyVariantRoot = new ShopifyVariantRoot();

	final ShopifyVariant shopifyVariant = new ShopifyVariant();
	shopifyVariant.setId("999");
	shopifyVariant.setBarcode("XYZ-123");
	shopifyVariant.setSku("ABC-123");
	shopifyVariant.setImageId("1");
	shopifyVariant.setPrice(BigDecimal.valueOf(42.11));
	shopifyVariant.setGrams(12);
	shopifyVariant.setAvailable(3L);
	shopifyVariant.setRequiresShipping(true);
	shopifyVariant.setTaxable(true);
	shopifyVariant.setOption1("Red");
	shopifyVariant.setOption2("Blue");
	shopifyVariant.setOption3("GREEN");
	shopifyVariantRoot.setVariant(shopifyVariant);

	final String expectedPath = new StringBuilder().append(FORWARD_SLASH).append(ShopifySdk.VARIANTS)
			.append(FORWARD_SLASH).append("999").toString();

	final String expectedResponseBodyString = getJsonString(ShopifyVariantRoot.class, shopifyVariantRoot);

	final Status expectedStatus = Status.OK;
	final int expectedStatusCode = expectedStatus.getStatusCode();
	driver.addExpectation(
			onRequestTo(expectedPath).withHeader(ShopifySdk.ACCESS_TOKEN_HEADER, accessToken)
					.withMethod(Method.GET),
			giveResponse(expectedResponseBodyString, MediaType.APPLICATION_JSON).withStatus(expectedStatusCode));

	final ShopifyVariant actualShopifyVariant = shopifySdk.getVariant("999");
	assertNotNull(actualShopifyVariant);

	assertEquals(shopifyVariant.getId(), actualShopifyVariant.getId());
	assertEquals(shopifyVariant.getPrice(), actualShopifyVariant.getPrice());
	assertEquals(shopifyVariant.getGrams(), actualShopifyVariant.getGrams());
	assertEquals(shopifyVariant.getImageId(), actualShopifyVariant.getImageId());
	assertEquals(shopifyVariant.getInventoryPolicy(), actualShopifyVariant.getInventoryPolicy());
	assertEquals(shopifyVariant.getSku(), actualShopifyVariant.getSku());
	assertEquals(shopifyVariant.getPosition(), actualShopifyVariant.getPosition());
	assertEquals(shopifyVariant.getProductId(), actualShopifyVariant.getProductId());
	assertEquals(shopifyVariant.getTitle(), actualShopifyVariant.getTitle());
	assertEquals(shopifyVariant.getCompareAtPrice(), actualShopifyVariant.getCompareAtPrice());
	assertEquals(shopifyVariant.getBarcode(), actualShopifyVariant.getBarcode());
	assertEquals(shopifyVariant.getFulfillmentService(), actualShopifyVariant.getFulfillmentService());
	assertEquals(shopifyVariant.getOption1(), actualShopifyVariant.getOption1());
	assertEquals(shopifyVariant.getOption2(), actualShopifyVariant.getOption2());
	assertEquals(shopifyVariant.getOption3(), actualShopifyVariant.getOption3());

}
 
Example 19
Source File: JoynrHttpException.java    From joynr with Apache License 2.0 4 votes vote down vote up
public JoynrHttpException(Status status, JoynrErrorCode errorCode, String message) {
    this(status.getStatusCode(), errorCode.getCode(), errorCode.getDescription() + ": " + message);
}
 
Example 20
Source File: ErrorMessage.java    From library with Apache License 2.0 2 votes vote down vote up
/**
 * Same as {@link #of(WebserviceException)} but this one receives a generic exception and the desired http status
 * code to be used as identification of the error
 *
 * @param exception the exception
 * @return the error message to be used as response
 */
public static ErrorMessage of(Throwable exception, Status status) {
    final String cause = exception.getCause() != null ? exception.getCause().getMessage() : "";
    return new ErrorMessage(status.getStatusCode(), exception.getMessage(), cause);
}