@Test public void testGetSubscription() throws IOException, JsonParseException { final String SUBSCRIPTION_ID = "subscription_id1"; SimpleDateFormat subscriptionDateFormat = new SimpleDateFormat(SaasAccountServiceProxy.SUBSCRIPTION_DATE_FORMAT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); String startDate = subscriptionDateFormat.format(cal.getTime()); cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); String endDate = subscriptionDateFormat.format(cal.getTime()); String testDescriptorJson = "{serviceId:" + SaasAccountServiceProxy.ON_PREMISES + ",id:" + SUBSCRIPTION_ID + ",startDate: \"" + startDate + "\",endDate:\"" + endDate + "\"}"; doReturn("[" + testDescriptorJson + "]") .when(transport) .doGet(endsWith("subscription/find/account?id=" + ACCOUNT_ID), eq(TOKEN)); SubscriptionDescriptor descriptor = saasAccountServiceProxy.getSubscription(SUBSCRIPTION, TOKEN, ACCOUNT_ID); assertNotNull(descriptor); assertEquals(descriptor.getServiceId(), "OnPremises"); assertEquals(descriptor.getId(), "subscription_id1"); assertEquals(descriptor.getStartDate(), startDate); assertEquals(descriptor.getEndDate(), endDate); assertTrue(descriptor.getProperties().isEmpty()); assertTrue(descriptor.getLinks().isEmpty()); }
@Test public void testGetSubscription() throws Exception { SaasUserCredentials testUserCredentials = new SaasUserCredentials(TEST_ACCOUNT_ID, TEST_ACCESS_TOKEN); SimpleDateFormat subscriptionDateFormat = new SimpleDateFormat(SaasAccountServiceProxy.SUBSCRIPTION_DATE_FORMAT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); String startDate = subscriptionDateFormat.format(cal.getTime()); cal.add(Calendar.DATE, 2); String endDate = subscriptionDateFormat.format(cal.getTime()); String testSubscriptionDescriptorJson = "{\n" + " \"description\": \"On-Prem Commercial 25 Users\",\n" + " \"startDate\" : \"" + startDate + "\",\n" + " \"endDate\" : \"" + endDate + "\",\n" + " \"links\": [\n" + " {\n" + " \"href\": \"https://codenvy-stg" + ".com/api/account/subscriptions/subscriptionoxmrh93dw3ceuegk\",\n" + " \"rel\": \"get subscription by id\",\n" + " \"produces\": \"application/json\",\n" + " \"parameters\": [],\n" + " \"method\": \"GET\"\n" + " }\n" + " ],\n" + " \"properties\": {\n" + " \"Users\": \"25\",\n" + " \"Package\": \"Commercial\"\n" + " },\n" + " \"id\": \"subscriptionoxmrh93dw3ceuegk\",\n" + " \"state\": \"ACTIVE\"\n" + "}"; SubscriptionDescriptor descriptor = DtoFactory.getInstance() .createDtoFromJson(testSubscriptionDescriptorJson, SubscriptionDescriptor.class); doReturn(descriptor) .when(mockFacade) .getSaasSubscription(SaasAccountServiceProxy.ON_PREMISES, testUserCredentials); service.saasUserCredentials = testUserCredentials; Response result = service.getOnPremisesSaasSubscription(); assertEquals(result.getStatus(), Response.Status.OK.getStatusCode()); SubscriptionDescriptor subscription = Commons.createDtoFromJson((String) result.getEntity(), SubscriptionDescriptor.class); assertEquals(subscription.getDescription(), "On-Prem Commercial 25 Users"); assertEquals(subscription.getStartDate(), startDate); assertEquals(subscription.getEndDate(), endDate); assertTrue(subscription.getLinks().isEmpty()); assertEquals(subscription.getId(), "subscriptionoxmrh93dw3ceuegk"); assertEquals(subscription.getState().name(), "ACTIVE"); assertEquals(subscription.getProperties().get("Users"), "25"); assertEquals(subscription.getProperties().get("Package"), "Commercial"); doThrow(new HttpException(500, "error")) .when(mockFacade) .getSaasSubscription(SaasAccountServiceProxy.ON_PREMISES, testUserCredentials); result = service.getOnPremisesSaasSubscription(); assertErrorResponse(result); }