diff --git a/sandbox/savvis/src/main/java/org/jclouds/savvis/config/SymphonyVPDCRestClientModule.java b/sandbox/savvis/src/main/java/org/jclouds/savvis/config/SymphonyVPDCRestClientModule.java index ecb01e1df2..f0bea68bd4 100644 --- a/sandbox/savvis/src/main/java/org/jclouds/savvis/config/SymphonyVPDCRestClientModule.java +++ b/sandbox/savvis/src/main/java/org/jclouds/savvis/config/SymphonyVPDCRestClientModule.java @@ -28,9 +28,11 @@ import org.jclouds.http.annotation.ServerError; import org.jclouds.savvis.SymphonyVPDCAsyncClient; import org.jclouds.savvis.SymphonyVPDCClient; import org.jclouds.savvis.handlers.SymphonyVPDCErrorHandler; +import org.jclouds.savvis.xml.SymphonyVPDCOrgListHandler; import org.jclouds.vcloud.VCloudExpressAsyncClient; import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.config.BaseVCloudExpressRestClientModule; +import org.jclouds.vcloud.xml.OrgListHandler; import com.google.inject.Provides; @@ -53,7 +55,15 @@ public class SymphonyVPDCRestClientModule extends return in; } + + @Override + protected void configure() { + super.configure(); + bind(OrgListHandler.class).to(SymphonyVPDCOrgListHandler.class); + } + +@Override protected void bindErrorHandlers() { bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(SymphonyVPDCErrorHandler.class); bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(SymphonyVPDCErrorHandler.class); diff --git a/sandbox/savvis/src/main/java/org/jclouds/savvis/xml/SymphonyVPDCOrgListHandler.java b/sandbox/savvis/src/main/java/org/jclouds/savvis/xml/SymphonyVPDCOrgListHandler.java new file mode 100644 index 0000000000..814f874454 --- /dev/null +++ b/sandbox/savvis/src/main/java/org/jclouds/savvis/xml/SymphonyVPDCOrgListHandler.java @@ -0,0 +1,58 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.savvis.xml; + +import static org.jclouds.vcloud.util.Utils.cleanseAttributes; +import static org.jclouds.vcloud.util.Utils.putReferenceType; + +import java.util.Map; + +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.xml.OrgListHandler; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Maps; + +/** + * @author Adrian Cole + */ +public class SymphonyVPDCOrgListHandler extends OrgListHandler { + + private Map org = Maps.newHashMap(); + + public Map getResult() { + return org; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { + Map attributes = cleanseAttributes(attrs); + if (qName.contains("vApp:Org")) { + String type = attributes.get("type"); + if (type != null) { + if (type.indexOf("org+xml") != -1) { + putReferenceType(org, attributes); + } + } + } + } + +} diff --git a/sandbox/savvis/src/test/java/org/jclouds/savvis/SymphonyVPDCClientLiveTest.java b/sandbox/savvis/src/test/java/org/jclouds/savvis/SymphonyVPDCClientLiveTest.java index 4bd1afda95..7feaaa444c 100644 --- a/sandbox/savvis/src/test/java/org/jclouds/savvis/SymphonyVPDCClientLiveTest.java +++ b/sandbox/savvis/src/test/java/org/jclouds/savvis/SymphonyVPDCClientLiveTest.java @@ -21,8 +21,10 @@ package org.jclouds.savvis; import java.util.Properties; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.VCloudExpressClientLiveTest; import org.testng.annotations.BeforeGroups; @@ -47,9 +49,18 @@ public class SymphonyVPDCClientLiveTest extends VCloudExpressClientLiveTest { restProperties.setProperty("savvis-symphony-vpdc.propertiesbuilder", "org.jclouds.savvis.SymphonyVPDCPropertiesBuilder"); - context = new ComputeServiceContextFactory(restProperties).createContext(provider, + context = new ComputeServiceContextFactory(restProperties).createContext(provider, "kedar.dave", "gravSavvis1!", ImmutableSet. of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); + System.out.println(context); + + /*Properties overrides1 = new Properties(); + ComputeServiceContext context1 = + new ComputeServiceContextFactory(restProperties).createContext(provider,"kedar.dave" ,"gravSavvis1!",ImmutableSet. of(new JschSshClientModule()), overrides1); + System.out.println(context1.getComputeService().listImages()); + System.out.println(context1.getComputeService().listHardwareProfiles());*/ + connection = context.getApi(); + System.out.println(connection); } } \ No newline at end of file diff --git a/sandbox/savvis/src/test/java/org/jclouds/savvis/xml/SymphonyVPDCOrgListHandlerTest.java b/sandbox/savvis/src/test/java/org/jclouds/savvis/xml/SymphonyVPDCOrgListHandlerTest.java new file mode 100644 index 0000000000..1caccfbbd8 --- /dev/null +++ b/sandbox/savvis/src/test/java/org/jclouds/savvis/xml/SymphonyVPDCOrgListHandlerTest.java @@ -0,0 +1,52 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.savvis.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.util.Map; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.VCloudExpressMediaType; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +/** + * Tests behavior of {@code OrgListHandler} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "OrgListHandlerTest") +public class SymphonyVPDCOrgListHandlerTest extends BaseHandlerTest { + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/orglist.xml"); + + Map result = factory.create(injector.getInstance(SymphonyVPDCOrgListHandler.class)).parse(is); + assertEquals(result, ImmutableMap.of("SAVVISStation Integration Testing", new ReferenceTypeImpl("SAVVISStation Integration Testing", + VCloudExpressMediaType.ORG_XML, URI.create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0")))); + } +} diff --git a/sandbox/savvis/src/test/resources/orglist.xml b/sandbox/savvis/src/test/resources/orglist.xml new file mode 100644 index 0000000000..8ea8088fb8 --- /dev/null +++ b/sandbox/savvis/src/test/resources/orglist.xml @@ -0,0 +1,35 @@ + + + + + + + \ No newline at end of file