ParseLoginResponseFromHeaders implements Function<HttpResponse, VCloudSession> { public VCloudSession apply(HttpResponse from) { try { final String token = parseTokenFromHeaders(from); final Map<String, ReferenceType> org = factory.create(orgHandlerProvider.get()).parse( checkNotNull(from.getPayload().getInput(), "no payload in http response to login request %s", from)); return new VCloudSession() { @VCloudToken public String getVCloudToken() { return token; } @Org public Map<String, ReferenceType> getOrgs() { return org; } }; } finally { releasePayload(from); } } @Inject private  ParseLoginResponseFromHeaders(Factory factory, Provider<OrgListHandler> orgHandlerProvider); VCloudSession apply(HttpResponse from); String parseTokenFromHeaders(HttpResponse from);  }
@Test public void testApply() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("x-vcloud-authorization", "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", TerremarkVCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyBlueLock() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("x-vcloud-authorization", "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0="); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", TerremarkVCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyTerremark() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", TerremarkVCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyTerremarkMultipleCookies() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("Set-Cookie", "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly") .addHeader("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", TerremarkVCloudMediaType.ORG_XML, URI.create("https: }
@Test(expectedExceptions = HttpResponseException.class) public void testUnmatchedCookieThrowsHttpResponseException() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("Set-Cookie", "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); parser.apply(response); }
@Test(expectedExceptions = HttpResponseException.class) public void testNoThrowsHttpResponseException() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")).build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); parser.apply(response); }
@Test public void testApplyVirtacore() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("x-vcloud-authorization", "vcloud-token=IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48=").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48="); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", TerremarkVCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApply() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("x-vcloud-authorization", "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", VCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyBlueLock() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("x-vcloud-authorization", "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0="); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", VCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyTerremark() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", VCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyTerremarkMultipleCookies() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("Set-Cookie", "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly") .addHeader("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "37ce2715-9aba-4f48-8e45-2db8a8da702d"); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", VCloudMediaType.ORG_XML, URI.create("https: }
@Test public void testApplyVirtacore() { HttpResponse response = HttpResponse.builder().statusCode(200).message("OK") .payload(getClass().getResourceAsStream("/orglist.xml")) .addHeader("x-vcloud-authorization", "vcloud-token=IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48=").build(); response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8"); response.getPayload().getContentMetadata().setContentLength(307l); VCloudSession reply = parser.apply(response); assertEquals(reply.getVCloudToken(), "IPy0w7UGD4lwtdWAK/ZVzfuLK+dztxGRqsOhWqV0i48="); assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org", VCloudMediaType.ORG_XML, URI.create("https: }