JBoss Tools SVN: r31420 - in trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test: src/org/jboss/tools/internal/deltacloud/client/test and 7 other directories.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-05-23 03:28:29 -0400 (Mon, 23 May 2011)
New Revision: 31420
Added:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java
Removed:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/job/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/ui/preferences/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/test/core/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/test/ui/
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/META-INF/MANIFEST.MF
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientTestSuite.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/context/MockIntegrationTestContext.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/APIResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/HardwareProfileResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ImageResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/InstanceResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/KeyResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/RealmResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerFake.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerResponseFakes.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/utils/test/UrlBuilderTest.java
Log:
[JBIDE-8975] corrected package structure in Deltacloud client tests
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/META-INF/MANIFEST.MF 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/META-INF/MANIFEST.MF 2011-05-23 07:28:29 UTC (rev 31420)
@@ -5,7 +5,6 @@
Bundle-Version: 1.0.1.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.jboss.tools.deltacloud.client;bundle-version="0.1.0",
- org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
org.junit;bundle-version="[4.8.0,5.0.0)"
Bundle-ClassPath: jruby-complete-1.5.3.jar,
.
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientIntegrationTestSuite.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,19 +1,27 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.ImageMockIntegrationTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.InstanceMockIntegrationTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.KeyMockIntegrationTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.ServerTypeMockIntegrationTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.ImageMockIntegrationTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.InstanceMockIntegrationTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.KeyMockIntegrationTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.ServerTypeMockIntegrationTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientTestSuite.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientTestSuite.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/DeltaCloudClientTestSuite.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,21 +1,29 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.APIDomUnmarshallingTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.HardwareProfileDomUnmarshallingTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.ImageDomUnmarshallingTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.InstanceDomUnmarshallingTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.KeyDomUnmarshallingTest;
-import org.jboss.tools.internal.deltacloud.client.test.core.client.RealmDomUnmarshallingTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.APIDomUnmarshallingTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.HardwareProfileDomUnmarshallingTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.ImageDomUnmarshallingTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.InstanceDomUnmarshallingTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.KeyDomUnmarshallingTest;
+import org.jboss.tools.internal.deltacloud.client.test.client.RealmDomUnmarshallingTest;
import org.jboss.tools.internal.deltacloud.client.utils.test.UrlBuilderTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/APIDomUnmarshallingTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.net.MalformedURLException;
-
-import org.jboss.tools.deltacloud.core.client.API;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.API.Driver;
-import org.jboss.tools.deltacloud.core.client.unmarshal.APIUnmarshaller;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.APIResponseFakes.APIResponse;
-import org.junit.Test;
-
-/**
- * @author André Dietisheim
- */
-public class APIDomUnmarshallingTest {
-
- @Test
- public void ec2DriverIsUnmarshalled() throws MalformedURLException, DeltaCloudClientException {
- API api = new API();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(APIResponse.apiResponse.getBytes());
- new APIUnmarshaller().unmarshall(inputStream, api);
- assertNotNull(api);
- assertEquals(APIResponse.driver, api.getDriver().name().toLowerCase());
- }
-
- @Test
- public void invalidDriverUnmarshalledToUnknown() throws MalformedURLException, DeltaCloudClientException {
- API api = new API();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(APIResponse.invalidDriverApiResponse.getBytes());
- new APIUnmarshaller().unmarshall(inputStream, api);
- assertNotNull(api);
- assertEquals(Driver.UNKNOWN, api.getDriver());
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/APIDomUnmarshallingTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/APIDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,56 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.net.MalformedURLException;
+
+import org.jboss.tools.deltacloud.client.API;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.API.Driver;
+import org.jboss.tools.deltacloud.client.unmarshal.APIUnmarshaller;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.APIResponseFakes.APIResponse;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class APIDomUnmarshallingTest {
+
+ @Test
+ public void ec2DriverIsUnmarshalled() throws MalformedURLException, DeltaCloudClientException {
+ API api = new API();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(APIResponse.apiResponse.getBytes());
+ new APIUnmarshaller().unmarshall(inputStream, api);
+ assertNotNull(api);
+ assertEquals(APIResponse.driver, api.getDriver().name().toLowerCase());
+ }
+
+ @Test
+ public void invalidDriverUnmarshalledToUnknown() throws MalformedURLException, DeltaCloudClientException {
+ API api = new API();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(APIResponse.invalidDriverApiResponse.getBytes());
+ new APIUnmarshaller().unmarshall(inputStream, api);
+ assertNotNull(api);
+ assertEquals(Driver.UNKNOWN, api.getDriver());
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/HardwareProfileDomUnmarshallingTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.JAXBException;
-
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.HardwareProfile;
-import org.jboss.tools.deltacloud.core.client.Property;
-import org.jboss.tools.deltacloud.core.client.unmarshal.HardwareProfileUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.HardwareProfilesUnmarshaller;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.HardwareProfileResponseFakes.HardwareProfile1Response;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.HardwareProfileResponseFakes.HardwareProfile2Response;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.HardwareProfileResponseFakes.HardwareProfilesResponse;
-import org.junit.Test;
-
-/**
- * @author André Dietisheim
- */
-public class HardwareProfileDomUnmarshallingTest {
-
- @Test
- public void HardwareProfilesCanBeUnmarshalled() throws MalformedURLException, JAXBException,
- DeltaCloudClientException {
- List<HardwareProfile> profiles = new ArrayList<HardwareProfile>();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(HardwareProfilesResponse.response.getBytes());
- new HardwareProfilesUnmarshaller().unmarshall(inputStream, profiles);
- assertEquals(2, profiles.size());
- }
-
- @Test
- public void fixedPropertyHardwareProfileMayBeUnmarshalled() throws MalformedURLException, JAXBException,
- DeltaCloudClientException {
- HardwareProfile profile = new HardwareProfile();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(HardwareProfile1Response.response.getBytes());
- new HardwareProfileUnmarshaller().unmarshall(inputStream, profile);
- assertNotNull(profile);
- assertEquals(HardwareProfile1Response.id, profile.getId());
- assertEquals(HardwareProfile1Response.propMemValue + ' ' + HardwareProfile1Response.propMemUnit,
- profile.getMemory());
- assertEquals(HardwareProfile1Response.propStorageValue + ' ' + HardwareProfile1Response.propStorageUnit,
- profile.getStorage());
- assertEquals(HardwareProfile1Response.propCPUValue, profile.getCPU());
- assertEquals(HardwareProfile1Response.propArchValue, profile.getArchitecture());
- }
-
- @Test
- public void mixedPropertiesHardwareProfileMayBeUnmarshalled() throws MalformedURLException, JAXBException,
- DeltaCloudClientException {
- HardwareProfile profile = new HardwareProfile();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(HardwareProfile2Response.response.getBytes());
- new HardwareProfileUnmarshaller().unmarshall(inputStream, profile);
- assertNotNull(profile);
- assertEquals(HardwareProfile2Response.id, profile.getId());
- assertEquals(HardwareProfile2Response.propMemValue + ' ' + HardwareProfile2Response.propMemUnit,
- profile.getMemory());
- Property property = profile.getNamedProperty(Property.Names.MEMORY);
- assertNotNull(property);
- assertEquals(HardwareProfile2Response.propMemRangeFirst, property.getRange().getFirst());
- assertEquals(HardwareProfile2Response.propMemRangeLast, property.getRange().getLast());
- assertEquals(HardwareProfile2Response.propStorageValue + ' ' + HardwareProfile2Response.propStorageUnit,
- profile.getStorage());
- property = profile.getNamedProperty(Property.Names.STORAGE);
- assertNotNull(property);
- assertNotNull(property.getEnums());
- assertEquals(2, property.getEnums().size());
- assertEquals(HardwareProfile2Response.propStorageEnum1, property.getEnums().get(0));
- assertEquals(HardwareProfile2Response.propStorageEnum2, property.getEnums().get(1));
- assertEquals(HardwareProfile2Response.propCPUValue, profile.getCPU());
- assertEquals(HardwareProfile2Response.propArchValue, profile.getArchitecture());
- }
-
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/HardwareProfileDomUnmarshallingTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/HardwareProfileDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.HardwareProfile;
+import org.jboss.tools.deltacloud.client.Property;
+import org.jboss.tools.deltacloud.client.unmarshal.HardwareProfileUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.HardwareProfilesUnmarshaller;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.HardwareProfileResponseFakes.HardwareProfile1Response;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.HardwareProfileResponseFakes.HardwareProfile2Response;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.HardwareProfileResponseFakes.HardwareProfilesResponse;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class HardwareProfileDomUnmarshallingTest {
+
+ @Test
+ public void HardwareProfilesCanBeUnmarshalled() throws MalformedURLException, JAXBException,
+ DeltaCloudClientException {
+ List<HardwareProfile> profiles = new ArrayList<HardwareProfile>();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(HardwareProfilesResponse.response.getBytes());
+ new HardwareProfilesUnmarshaller().unmarshall(inputStream, profiles);
+ assertEquals(2, profiles.size());
+ }
+
+ @Test
+ public void fixedPropertyHardwareProfileMayBeUnmarshalled() throws MalformedURLException, JAXBException,
+ DeltaCloudClientException {
+ HardwareProfile profile = new HardwareProfile();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(HardwareProfile1Response.response.getBytes());
+ new HardwareProfileUnmarshaller().unmarshall(inputStream, profile);
+ assertNotNull(profile);
+ assertEquals(HardwareProfile1Response.id, profile.getId());
+ assertEquals(HardwareProfile1Response.propMemValue + ' ' + HardwareProfile1Response.propMemUnit,
+ profile.getMemory());
+ assertEquals(HardwareProfile1Response.propStorageValue + ' ' + HardwareProfile1Response.propStorageUnit,
+ profile.getStorage());
+ assertEquals(HardwareProfile1Response.propCPUValue, profile.getCPU());
+ assertEquals(HardwareProfile1Response.propArchValue, profile.getArchitecture());
+ }
+
+ @Test
+ public void mixedPropertiesHardwareProfileMayBeUnmarshalled() throws MalformedURLException, JAXBException,
+ DeltaCloudClientException {
+ HardwareProfile profile = new HardwareProfile();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(HardwareProfile2Response.response.getBytes());
+ new HardwareProfileUnmarshaller().unmarshall(inputStream, profile);
+ assertNotNull(profile);
+ assertEquals(HardwareProfile2Response.id, profile.getId());
+ assertEquals(HardwareProfile2Response.propMemValue + ' ' + HardwareProfile2Response.propMemUnit,
+ profile.getMemory());
+ Property property = profile.getNamedProperty(Property.Names.MEMORY);
+ assertNotNull(property);
+ assertEquals(HardwareProfile2Response.propMemRangeFirst, property.getRange().getFirst());
+ assertEquals(HardwareProfile2Response.propMemRangeLast, property.getRange().getLast());
+ assertEquals(HardwareProfile2Response.propStorageValue + ' ' + HardwareProfile2Response.propStorageUnit,
+ profile.getStorage());
+ property = profile.getNamedProperty(Property.Names.STORAGE);
+ assertNotNull(property);
+ assertNotNull(property.getEnums());
+ assertEquals(2, property.getEnums().size());
+ assertEquals(HardwareProfile2Response.propStorageEnum1, property.getEnums().get(0));
+ assertEquals(HardwareProfile2Response.propStorageEnum2, property.getEnums().get(1));
+ assertEquals(HardwareProfile2Response.propCPUValue, profile.getCPU());
+ assertEquals(HardwareProfile2Response.propArchValue, profile.getArchitecture());
+ }
+
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ImageDomUnmarshallingTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.Image;
-import org.jboss.tools.deltacloud.core.client.unmarshal.ImageUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.ImagesUnmarshaller;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.ImageResponseFakes.ImageResponse;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.ImageResponseFakes.ImagesResponse;
-import org.junit.Test;
-
-/**
- * @author André Dietisheim
- */
-public class ImageDomUnmarshallingTest {
-
- @Test
- public void imageMayBeUnmarshalled() throws DeltaCloudClientException {
- Image image = new Image();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(ImageResponse.response.getBytes());
- new ImageUnmarshaller().unmarshall(inputStream, image);
- assertNotNull(image);
- assertEquals(ImageResponse.id, image.getId());
- assertEquals(ImageResponse.name, image.getName());
- assertEquals(ImageResponse.ownerId, image.getOwnerId());
- assertEquals(ImageResponse.description, image.getDescription());
- assertEquals(ImageResponse.architecture, image.getArchitecture());
- }
-
- @Test
- public void imagesMayBeUnmarshalled() throws DeltaCloudClientException {
- ByteArrayInputStream inputStream = new ByteArrayInputStream(ImagesResponse.response.getBytes());
- List<Image> images = new ArrayList<Image>();
- new ImagesUnmarshaller().unmarshall(inputStream, images);
- assertEquals(2, images.size());
-
- Image image = images.get(0);
- assertEquals(ImagesResponse.id1, image.getId());
- assertEquals(ImagesResponse.name1, image.getName());
-
- image = images.get(1);
- assertEquals(ImagesResponse.id2, image.getId());
- assertEquals(ImagesResponse.name2, image.getName());
- }
-
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ImageDomUnmarshallingTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,70 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.Image;
+import org.jboss.tools.deltacloud.client.unmarshal.ImageUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.ImagesUnmarshaller;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.ImageResponseFakes.ImageResponse;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.ImageResponseFakes.ImagesResponse;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class ImageDomUnmarshallingTest {
+
+ @Test
+ public void imageMayBeUnmarshalled() throws DeltaCloudClientException {
+ Image image = new Image();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(ImageResponse.response.getBytes());
+ new ImageUnmarshaller().unmarshall(inputStream, image);
+ assertNotNull(image);
+ assertEquals(ImageResponse.id, image.getId());
+ assertEquals(ImageResponse.name, image.getName());
+ assertEquals(ImageResponse.ownerId, image.getOwnerId());
+ assertEquals(ImageResponse.description, image.getDescription());
+ assertEquals(ImageResponse.architecture, image.getArchitecture());
+ }
+
+ @Test
+ public void imagesMayBeUnmarshalled() throws DeltaCloudClientException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(ImagesResponse.response.getBytes());
+ List<Image> images = new ArrayList<Image>();
+ new ImagesUnmarshaller().unmarshall(inputStream, images);
+ assertEquals(2, images.size());
+
+ Image image = images.get(0);
+ assertEquals(ImagesResponse.id1, image.getId());
+ assertEquals(ImagesResponse.name1, image.getName());
+
+ image = images.get(1);
+ assertEquals(ImagesResponse.id2, image.getId());
+ assertEquals(ImagesResponse.name2, image.getName());
+ }
+
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ImageMockIntegrationTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.util.Collection;
-import java.util.List;
-
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.Image;
-import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * An integration test that test various image related operations in DeltaCloudClient
- *
- * @author Andre Dietisheim
- *
- * @see DeltaCloudClientImpl#listImages()
- * @see DeltaCloudClientImpl#listImages(String)
- *
- */
-public class ImageMockIntegrationTest {
-
- private MockIntegrationTestContext testSetup;
-
- @Before
- public void setUp() throws IOException, DeltaCloudClientException {
- this.testSetup = new MockIntegrationTestContext();
- testSetup.setUp();
- }
-
- @After
- public void tearDown() {
- testSetup.tearDown();
- }
-
- @Test(expected = DeltaCloudClientException.class)
- public void cannotListIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
- DeltaCloudClientImpl client = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser", "badPassword");
- client.listImages();
- }
-
- @Test
- public void assertDefaultImages() throws DeltaCloudClientException {
- List<Image> images = testSetup.getClient().listImages();
- assertEquals(3, images.size());
- assertImage("img1", "Fedora 10", "fedoraproject", "Fedora 10", "x86_64", getImage("img1", images));
- assertImage("img2", "Fedora 10", "fedoraproject", "Fedora 10", "i386", getImage("img2", images) );
- assertImage("img3", "JBoss", "mockuser", "JBoss", "i386", getImage("img3", images));
- }
-
- private Image getImage(String id, Collection<Image> images) {
- for (Image image : images) {
- if (id.equals(image.getId())) {
- return image;
- }
- }
- fail("image " + id + " was not found");
- return null;
- }
-
- private void assertImage(String id, String name, String owner, String description, String architecture, Image image) {
- assertEquals(id, image.getId());
- assertEquals(name, image.getName());
- assertEquals(owner, image.getOwnerId());
- assertEquals(architecture, image.getArchitecture());
- assertEquals(description, image.getDescription());
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ImageMockIntegrationTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ImageMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,93 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.client.Image;
+import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * An integration test that test various image related operations in DeltaCloudClient
+ *
+ * @author Andre Dietisheim
+ *
+ * @see DeltaCloudClientImpl#listImages()
+ * @see DeltaCloudClientImpl#listImages(String)
+ *
+ */
+public class ImageMockIntegrationTest {
+
+ private MockIntegrationTestContext testSetup;
+
+ @Before
+ public void setUp() throws IOException, DeltaCloudClientException {
+ this.testSetup = new MockIntegrationTestContext();
+ testSetup.setUp();
+ }
+
+ @After
+ public void tearDown() {
+ testSetup.tearDown();
+ }
+
+ @Test(expected = DeltaCloudClientException.class)
+ public void cannotListIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
+ DeltaCloudClientImpl client = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser", "badPassword");
+ client.listImages();
+ }
+
+ @Test
+ public void assertDefaultImages() throws DeltaCloudClientException {
+ List<Image> images = testSetup.getClient().listImages();
+ assertEquals(3, images.size());
+ assertImage("img1", "Fedora 10", "fedoraproject", "Fedora 10", "x86_64", getImage("img1", images));
+ assertImage("img2", "Fedora 10", "fedoraproject", "Fedora 10", "i386", getImage("img2", images) );
+ assertImage("img3", "JBoss", "mockuser", "JBoss", "i386", getImage("img3", images));
+ }
+
+ private Image getImage(String id, Collection<Image> images) {
+ for (Image image : images) {
+ if (id.equals(image.getId())) {
+ return image;
+ }
+ }
+ fail("image " + id + " was not found");
+ return null;
+ }
+
+ private void assertImage(String id, String name, String owner, String description, String architecture, Image image) {
+ assertEquals(id, image.getId());
+ assertEquals(name, image.getName());
+ assertEquals(owner, image.getOwnerId());
+ assertEquals(architecture, image.getArchitecture());
+ assertEquals(description, image.getDescription());
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/InstanceDomUnmarshallingTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.JAXBException;
-
-import org.jboss.tools.deltacloud.core.client.Action;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.Instance;
-import org.jboss.tools.deltacloud.core.client.unmarshal.ActionUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.InstanceUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.InstancesUnmarshaller;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.InstanceResponseFakes.InstanceActionResponse;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.InstanceResponseFakes.InstanceResponse;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.InstanceResponseFakes.InstancesResponse;
-import org.junit.Test;
-
-/**
- * @author André Dietisheim
- */
-public class InstanceDomUnmarshallingTest {
-
- @Test
- public void instanceActionMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
- Action<Instance> instanceAction = new Action<Instance>();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(InstanceActionResponse.response.getBytes());
- new ActionUnmarshaller<Instance>().unmarshall(inputStream, instanceAction);
- assertNotNull(instanceAction);
- assertEquals(InstanceActionResponse.name, instanceAction.getName());
- assertEquals(InstanceActionResponse.url, instanceAction.getUrl().toString());
- assertEquals(InstanceActionResponse.method.toUpperCase(), instanceAction.getMethod().toString().toUpperCase());
- }
-
- @Test
- public void instanceMayBeUnmarshalled() throws DeltaCloudClientException {
- Instance instance = new Instance();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(InstanceResponse.response.getBytes());
- new InstanceUnmarshaller().unmarshall(inputStream, instance);
- assertNotNull(instance);
- assertEquals(InstanceResponse.id1, instance.getId());
- assertEquals(InstanceResponse.name1, instance.getName());
- assertEquals(InstanceResponse.ownerId1, instance.getOwnerId());
- assertEquals(InstanceResponse.image1Id, instance.getImageId());
- assertEquals(InstanceResponse.hardwareProfile1Id, instance.getProfileId());
- assertEquals(InstanceResponse.realm1Id, instance.getRealmId());
- assertEquals(InstanceResponse.state, instance.getState());
- assertEquals(InstanceResponse.keyname1, instance.getKeyId());
- assertEquals(2, instance.getActions().size());
- assertEquals(InstanceResponse.actionNameStop, instance.getActions().get(0).getName());
- assertEquals(InstanceResponse.actionNameReboot, instance.getActions().get(1).getName());
- assertEquals(1, instance.getPublicAddresses().size());
- assertEquals(InstanceResponse.publicAddress1, instance.getPublicAddresses().get(0));
- assertEquals(1, instance.getPrivateAddresses().size());
- assertEquals(InstanceResponse.privateAddress1, instance.getPrivateAddresses().get(0));
-
- }
-
- @Test
- public void instancesMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
- ByteArrayInputStream inputStream = new ByteArrayInputStream(InstancesResponse.response.getBytes());
- List<Instance> instances = new ArrayList<Instance>();
- new InstancesUnmarshaller().unmarshall(inputStream, instances);
- assertEquals(2, instances.size());
-
- Instance instance = instances.get(0);
- assertEquals(InstancesResponse.id1, instance.getId());
- assertEquals(InstancesResponse.name1, instance.getName());
-
- instance = instances.get(1);
- assertEquals(InstancesResponse.id2, instance.getId());
- assertEquals(InstancesResponse.name2, instance.getName());
- assertEquals(2, instance.getActions().size());
- }
-
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/InstanceDomUnmarshallingTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,99 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.Instance;
+import org.jboss.tools.deltacloud.client.unmarshal.ActionUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.InstanceUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.InstancesUnmarshaller;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.InstanceResponseFakes.InstanceActionResponse;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.InstanceResponseFakes.InstanceResponse;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.InstanceResponseFakes.InstancesResponse;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class InstanceDomUnmarshallingTest {
+
+ @Test
+ public void instanceActionMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
+ Action<Instance> instanceAction = new Action<Instance>();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(InstanceActionResponse.response.getBytes());
+ new ActionUnmarshaller<Instance>().unmarshall(inputStream, instanceAction);
+ assertNotNull(instanceAction);
+ assertEquals(InstanceActionResponse.name, instanceAction.getName());
+ assertEquals(InstanceActionResponse.url, instanceAction.getUrl().toString());
+ assertEquals(InstanceActionResponse.method.toUpperCase(), instanceAction.getMethod().toString().toUpperCase());
+ }
+
+ @Test
+ public void instanceMayBeUnmarshalled() throws DeltaCloudClientException {
+ Instance instance = new Instance();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(InstanceResponse.response.getBytes());
+ new InstanceUnmarshaller().unmarshall(inputStream, instance);
+ assertNotNull(instance);
+ assertEquals(InstanceResponse.id1, instance.getId());
+ assertEquals(InstanceResponse.name1, instance.getName());
+ assertEquals(InstanceResponse.ownerId1, instance.getOwnerId());
+ assertEquals(InstanceResponse.image1Id, instance.getImageId());
+ assertEquals(InstanceResponse.hardwareProfile1Id, instance.getProfileId());
+ assertEquals(InstanceResponse.realm1Id, instance.getRealmId());
+ assertEquals(InstanceResponse.state, instance.getState());
+ assertEquals(InstanceResponse.keyname1, instance.getKeyId());
+ assertEquals(2, instance.getActions().size());
+ assertEquals(InstanceResponse.actionNameStop, instance.getActions().get(0).getName());
+ assertEquals(InstanceResponse.actionNameReboot, instance.getActions().get(1).getName());
+ assertEquals(1, instance.getPublicAddresses().size());
+ assertEquals(InstanceResponse.publicAddress1, instance.getPublicAddresses().get(0));
+ assertEquals(1, instance.getPrivateAddresses().size());
+ assertEquals(InstanceResponse.privateAddress1, instance.getPrivateAddresses().get(0));
+
+ }
+
+ @Test
+ public void instancesMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(InstancesResponse.response.getBytes());
+ List<Instance> instances = new ArrayList<Instance>();
+ new InstancesUnmarshaller().unmarshall(inputStream, instances);
+ assertEquals(2, instances.size());
+
+ Instance instance = instances.get(0);
+ assertEquals(InstancesResponse.id1, instance.getId());
+ assertEquals(InstancesResponse.name1, instance.getName());
+
+ instance = instances.get(1);
+ assertEquals(InstancesResponse.id2, instance.getId());
+ assertEquals(InstancesResponse.name2, instance.getName());
+ assertEquals(2, instance.getActions().size());
+ }
+
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/InstanceMockIntegrationTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,272 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-
-import org.jboss.tools.deltacloud.core.client.Action;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
-import org.jboss.tools.deltacloud.core.client.HttpMethod;
-import org.jboss.tools.deltacloud.core.client.Image;
-import org.jboss.tools.deltacloud.core.client.Instance;
-import org.jboss.tools.deltacloud.core.client.StateAware.State;
-import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Integration tests for instance related methods in
- * {@link DeltaCloudClientImpl}.
- *
- * @author Andre Dietisheim
- *
- * @see DeltaCloudClientImpl#listInstances()
- * @see DeltaCloudClientImpl#createInstance(String)
- * @see DeltaCloudClientImpl#destroyInstance(String)
- * @see DeltaCloudClientImpl#startInstance(String)
- * @see DeltaCloudClientImpl#shutdownInstance(String)
- */
-public class InstanceMockIntegrationTest {
-
- private MockIntegrationTestContext testSetup;
-
- @Before
- public void setUp() throws IOException, DeltaCloudClientException {
- this.testSetup = new MockIntegrationTestContext();
- testSetup.setUp();
- }
-
- @After
- public void tearDown() {
- testSetup.tearDown();
- }
-
- /**
- * #listInstance contains the test instance created in {@link #setUp()}
- *
- * @throws DeltaCloudClientException
- * the delta cloud client exception
- */
-
- @Test
- public void listContainsTestInstance() throws DeltaCloudClientException {
- DeltaCloudClient client = testSetup.getClient();
- List<Instance> instances = client.listInstances();
- assertTrue(instances.size() > 0);
- Instance testInstance = testSetup.getTestInstance();
- assertNotNull(testSetup.getInstanceById(testInstance.getId(), client));
- }
-
- @Test
- public void listTestInstance() throws DeltaCloudClientException {
- Instance instance = testSetup.getClient().listInstances(testSetup.getTestInstance().getId());
- assertNotNull(instance);
- Instance testInstance = testSetup.getTestInstance();
- assertEquals(testInstance.getId(), instance.getId());
- assertInstance(
- testInstance.getName()
- , testInstance.getOwnerId()
- , testInstance.getImageId()
- , testInstance.getRealmId()
- , testInstance.getProfileId()
- , testInstance.getMemory()
- , testInstance.getPrivateAddresses()
- , testInstance.getPublicAddresses()
- , instance);
- }
-
- @Test(expected = DeltaCloudNotFoundClientException.class)
- public void listDestroyedInstanceThrowsException() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- testSetup.quietlyDestroyInstance(testInstance);
- testSetup.getClient().listInstances(testInstance.getId());
- }
-
- private void assertInstance(String name, String owner, String ImageId, String realmId, String profile,
- String memory, List<String> privateAddresses, List<String> publicAddresses, Instance instance) {
- assertNotNull("instance " + name + " was not found", instance);
- assertEquals(name, instance.getName());
- assertEquals(owner, instance.getOwnerId());
- assertEquals(realmId, instance.getRealmId());
- assertEquals(profile, instance.getProfileId());
- assertEquals(memory, instance.getMemory());
- assertTrue(privateAddresses.equals(instance.getPrivateAddresses()));
- assertTrue(publicAddresses.equals(instance.getPublicAddresses()));
- }
-
- @Test(expected = DeltaCloudClientException.class)
- public void cannotDestroyIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
- DeltaCloudClientImpl unauthenticatedClient = new DeltaCloudClientImpl(
- MockIntegrationTestContext.DELTACLOUD_URL,
- "badUser", "badPassword");
- Image image = testSetup.getFirstImage(unauthenticatedClient);
- unauthenticatedClient.createInstance(image.getId());
- }
-
- @Test
- public void canCreateInstance() throws DeltaCloudClientException {
- Instance instance = null;
- try {
- Image image = testSetup.getFirstImage(testSetup.getClient());
- instance = testSetup.getClient().createInstance(image.getId());
- assertTrue(instance != null);
- assertEquals(image.getId(), instance.getImageId());
- assertEquals(State.RUNNING, instance.getState());
- } finally {
- testSetup.quietlyDestroyInstance(instance);
- }
- }
-
- @Test(expected = DeltaCloudClientException.class)
- public void cannotDestroyUnknownImageId() throws DeltaCloudClientException {
- testSetup.getClient().createInstance("dummy");
- }
-
- @Test(expected=DeltaCloudClientException.class)
- public void canDestroy() throws DeltaCloudClientException {
- Image image = testSetup.getFirstImage(testSetup.getClient());
- DeltaCloudClient client = testSetup.getClient();
- Instance instance = client.createInstance(image.getId());
- instance.stop(client);
- instance.destroy(client);
- client.listInstances(instance.getId());
- }
-
- @Test(expected = DeltaCloudClientException.class)
- public void destroyThrowsExceptionOnUnknowInstanceId() throws DeltaCloudClientException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException,
- NoSuchMethodException {
- DeltaCloudClient client = testSetup.getClient();
- client.performAction(
- createInstanceAction(
- "destroy",
- MockIntegrationTestContext.DELTACLOUD_URL,
- HttpMethod.POST,
- new Instance()));
- }
-
- private Action<Instance> createInstanceAction(String name, String url, HttpMethod method, Instance instance) {
- Action<Instance> action = new Action<Instance>();
- action.setName(name);
- action.setMethod(method);
- action.setOwner(instance);
- return action;
- }
-
- @SuppressWarnings("unused")
- private class InstanceActionProxy implements InvocationHandler {
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getName().equals("getUrl")) {
- return MockIntegrationTestContext.DELTACLOUD_URL;
- } else if (method.getName().equals("getMethod")) {
- return HttpMethod.POST;
- } else {
- return null;
- }
- }
-
- }
-
- @Test
- public void canShutdownInstance() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- testInstance.stop(client);
- testInstance = client.listInstances(testInstance.getId()); // reload!
- assertEquals(State.STOPPED, testInstance.getState());
- }
-
- @Test
- public void canStartInstance() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- if (testInstance.getState() == State.RUNNING) {
- testInstance.stop(client);
- }
- testInstance.start(client);
- testInstance = client.listInstances(testInstance.getId()); // reload!
- assertEquals(State.RUNNING, testInstance.getState());
- }
-
- @Test
- public void canStartInstanceByAction() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- if (testInstance.getState() == State.RUNNING) {
- testInstance.stop(client);
- }
- assertTrue(testInstance.start(client));
- testInstance = client.listInstances(testInstance.getId()); // reload!
- assertEquals(State.RUNNING, testInstance.getState());
- }
-
- @Test
- public void cannotStartRunningInstance() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- testInstance.start(client);
- assertFalse(testInstance.start(client));
- }
-
- @Test
- public void cannotStopStoppedInstance() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- try {
- testInstance.stop(client);
- assertFalse(testInstance.stop(client));
- } finally {
- testInstance.start(client);
- }
- }
-
- @Test
- public void cannotDestroyRunningInstance() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- testInstance = client.listInstances(testInstance.getId()); // reload
- assertTrue(testInstance.getState() == State.RUNNING);
- assertFalse(testInstance.destroy(client));
- }
-
- @Test
- public void cannotRebootStoppedInstance() throws DeltaCloudClientException, InterruptedException,
- ExecutionException {
- Instance testInstance = testSetup.getTestInstance();
- DeltaCloudClient client = testSetup.getClient();
- try {
- testInstance.stop(client);
- testInstance = client.listInstances(testInstance.getId()); // reload
- assertTrue(testInstance.getState() == State.STOPPED);
- assertFalse(testInstance.reboot(client));
- } finally {
- testInstance.start(client);
- client.listInstances(testInstance.getId()); // reload
- }
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/InstanceMockIntegrationTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/InstanceMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,280 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.client.Image;
+import org.jboss.tools.deltacloud.client.Instance;
+import org.jboss.tools.deltacloud.client.StateAware.State;
+import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration tests for instance related methods in
+ * {@link DeltaCloudClientImpl}.
+ *
+ * @author Andre Dietisheim
+ *
+ * @see DeltaCloudClientImpl#listInstances()
+ * @see DeltaCloudClientImpl#createInstance(String)
+ * @see DeltaCloudClientImpl#destroyInstance(String)
+ * @see DeltaCloudClientImpl#startInstance(String)
+ * @see DeltaCloudClientImpl#shutdownInstance(String)
+ */
+public class InstanceMockIntegrationTest {
+
+ private MockIntegrationTestContext testSetup;
+
+ @Before
+ public void setUp() throws IOException, DeltaCloudClientException {
+ this.testSetup = new MockIntegrationTestContext();
+ testSetup.setUp();
+ }
+
+ @After
+ public void tearDown() {
+ testSetup.tearDown();
+ }
+
+ /**
+ * #listInstance contains the test instance created in {@link #setUp()}
+ *
+ * @throws DeltaCloudClientException
+ * the delta cloud client exception
+ */
+
+ @Test
+ public void listContainsTestInstance() throws DeltaCloudClientException {
+ DeltaCloudClient client = testSetup.getClient();
+ List<Instance> instances = client.listInstances();
+ assertTrue(instances.size() > 0);
+ Instance testInstance = testSetup.getTestInstance();
+ assertNotNull(testSetup.getInstanceById(testInstance.getId(), client));
+ }
+
+ @Test
+ public void listTestInstance() throws DeltaCloudClientException {
+ Instance instance = testSetup.getClient().listInstances(testSetup.getTestInstance().getId());
+ assertNotNull(instance);
+ Instance testInstance = testSetup.getTestInstance();
+ assertEquals(testInstance.getId(), instance.getId());
+ assertInstance(
+ testInstance.getName()
+ , testInstance.getOwnerId()
+ , testInstance.getImageId()
+ , testInstance.getRealmId()
+ , testInstance.getProfileId()
+ , testInstance.getMemory()
+ , testInstance.getPrivateAddresses()
+ , testInstance.getPublicAddresses()
+ , instance);
+ }
+
+ @Test(expected = DeltaCloudNotFoundClientException.class)
+ public void listDestroyedInstanceThrowsException() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ testSetup.quietlyDestroyInstance(testInstance);
+ testSetup.getClient().listInstances(testInstance.getId());
+ }
+
+ private void assertInstance(String name, String owner, String ImageId, String realmId, String profile,
+ String memory, List<String> privateAddresses, List<String> publicAddresses, Instance instance) {
+ assertNotNull("instance " + name + " was not found", instance);
+ assertEquals(name, instance.getName());
+ assertEquals(owner, instance.getOwnerId());
+ assertEquals(realmId, instance.getRealmId());
+ assertEquals(profile, instance.getProfileId());
+ assertEquals(memory, instance.getMemory());
+ assertTrue(privateAddresses.equals(instance.getPrivateAddresses()));
+ assertTrue(publicAddresses.equals(instance.getPublicAddresses()));
+ }
+
+ @Test(expected = DeltaCloudClientException.class)
+ public void cannotDestroyIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
+ DeltaCloudClientImpl unauthenticatedClient = new DeltaCloudClientImpl(
+ MockIntegrationTestContext.DELTACLOUD_URL,
+ "badUser", "badPassword");
+ Image image = testSetup.getFirstImage(unauthenticatedClient);
+ unauthenticatedClient.createInstance(image.getId());
+ }
+
+ @Test
+ public void canCreateInstance() throws DeltaCloudClientException {
+ Instance instance = null;
+ try {
+ Image image = testSetup.getFirstImage(testSetup.getClient());
+ instance = testSetup.getClient().createInstance(image.getId());
+ assertTrue(instance != null);
+ assertEquals(image.getId(), instance.getImageId());
+ assertEquals(State.RUNNING, instance.getState());
+ } finally {
+ testSetup.quietlyDestroyInstance(instance);
+ }
+ }
+
+ @Test(expected = DeltaCloudClientException.class)
+ public void cannotDestroyUnknownImageId() throws DeltaCloudClientException {
+ testSetup.getClient().createInstance("dummy");
+ }
+
+ @Test(expected=DeltaCloudClientException.class)
+ public void canDestroy() throws DeltaCloudClientException {
+ Image image = testSetup.getFirstImage(testSetup.getClient());
+ DeltaCloudClient client = testSetup.getClient();
+ Instance instance = client.createInstance(image.getId());
+ instance.stop(client);
+ instance.destroy(client);
+ client.listInstances(instance.getId());
+ }
+
+ @Test(expected = DeltaCloudClientException.class)
+ public void destroyThrowsExceptionOnUnknowInstanceId() throws DeltaCloudClientException, IllegalArgumentException,
+ InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException,
+ NoSuchMethodException {
+ DeltaCloudClient client = testSetup.getClient();
+ client.performAction(
+ createInstanceAction(
+ "destroy",
+ MockIntegrationTestContext.DELTACLOUD_URL,
+ HttpMethod.POST,
+ new Instance()));
+ }
+
+ private Action<Instance> createInstanceAction(String name, String url, HttpMethod method, Instance instance) {
+ Action<Instance> action = new Action<Instance>();
+ action.setName(name);
+ action.setMethod(method);
+ action.setOwner(instance);
+ return action;
+ }
+
+ @SuppressWarnings("unused")
+ private class InstanceActionProxy implements InvocationHandler {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (method.getName().equals("getUrl")) {
+ return MockIntegrationTestContext.DELTACLOUD_URL;
+ } else if (method.getName().equals("getMethod")) {
+ return HttpMethod.POST;
+ } else {
+ return null;
+ }
+ }
+
+ }
+
+ @Test
+ public void canShutdownInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ testInstance.stop(client);
+ testInstance = client.listInstances(testInstance.getId()); // reload!
+ assertEquals(State.STOPPED, testInstance.getState());
+ }
+
+ @Test
+ public void canStartInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ if (testInstance.getState() == State.RUNNING) {
+ testInstance.stop(client);
+ }
+ testInstance.start(client);
+ testInstance = client.listInstances(testInstance.getId()); // reload!
+ assertEquals(State.RUNNING, testInstance.getState());
+ }
+
+ @Test
+ public void canStartInstanceByAction() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ if (testInstance.getState() == State.RUNNING) {
+ testInstance.stop(client);
+ }
+ assertTrue(testInstance.start(client));
+ testInstance = client.listInstances(testInstance.getId()); // reload!
+ assertEquals(State.RUNNING, testInstance.getState());
+ }
+
+ @Test
+ public void cannotStartRunningInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ testInstance.start(client);
+ assertFalse(testInstance.start(client));
+ }
+
+ @Test
+ public void cannotStopStoppedInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ try {
+ testInstance.stop(client);
+ assertFalse(testInstance.stop(client));
+ } finally {
+ testInstance.start(client);
+ }
+ }
+
+ @Test
+ public void cannotDestroyRunningInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ testInstance = client.listInstances(testInstance.getId()); // reload
+ assertTrue(testInstance.getState() == State.RUNNING);
+ assertFalse(testInstance.destroy(client));
+ }
+
+ @Test
+ public void cannotRebootStoppedInstance() throws DeltaCloudClientException, InterruptedException,
+ ExecutionException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ try {
+ testInstance.stop(client);
+ testInstance = client.listInstances(testInstance.getId()); // reload
+ assertTrue(testInstance.getState() == State.STOPPED);
+ assertFalse(testInstance.reboot(client));
+ } finally {
+ testInstance.start(client);
+ client.listInstances(testInstance.getId()); // reload
+ }
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/KeyDomUnmarshallingTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.JAXBException;
-
-import org.jboss.tools.deltacloud.core.client.Action;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.HttpMethod;
-import org.jboss.tools.deltacloud.core.client.Key;
-import org.jboss.tools.deltacloud.core.client.unmarshal.ActionUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.KeyUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.KeysUnmarshaller;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes.KeyActionResponse;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes.KeyResponse;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes.KeysResponse;
-import org.junit.Test;
-
-/**
- * @author André Dietisheim
- */
-public class KeyDomUnmarshallingTest {
-
- @Test
- public void keyActionMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
- Action<Key> keyAction = new Action<Key>();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(KeyActionResponse.keyActionResponse.getBytes());
- new ActionUnmarshaller<Key>().unmarshall(inputStream, keyAction);
- assertNotNull(keyAction);
- assertEquals(KeyActionResponse.name, keyAction.getName());
- assertEquals(KeyActionResponse.url, keyAction.getUrl().toString());
- assertEquals(KeyActionResponse.method.toUpperCase(), keyAction.getMethod().toString().toUpperCase());
- }
-
- @Test
- public void keyMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
- Key key = new Key();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(KeyResponse.keyResponse.getBytes());
- new KeyUnmarshaller().unmarshall(inputStream, key);
- assertNotNull(key);
- assertEquals(KeyResponseFakes.KeyResponse.id, key.getId());
- assertEquals(KeyResponse.fingerprint, key.getFingerprint());
- assertEquals(new URL(KeyResponse.url), key.getUrl());
- assertEquals(KeyResponse.pem, key.getPem());
- assertEquals(1, key.getActions().size());
- Action<Key> action = key.getActions().get(0);
- assertNotNull(action);
- assertEquals(KeyResponse.url, action.getUrl().toString());
- assertEquals(KeyResponse.name, action.getName());
- assertEquals(HttpMethod.valueOf(KeyResponse.method.toUpperCase()), action.getMethod());
- }
-
- @Test
- public void keysMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
- ByteArrayInputStream inputStream = new ByteArrayInputStream(KeysResponse.keysResponse.getBytes());
- List<Key> keys = new ArrayList<Key>();
- new KeysUnmarshaller().unmarshall(inputStream, keys);
- assertEquals(2, keys.size());
- Key key = keys.get(0);
- assertEquals(KeysResponse.id1, key.getId());
- assertEquals(KeysResponse.fingerprint1, key.getFingerprint());
- assertEquals(new URL(KeysResponse.url1), key.getUrl());
- assertEquals(KeysResponse.pem1, key.getPem());
- assertEquals(1, key.getActions().size());
- Action<Key> action = key.getActions().get(0);
- assertNotNull(action);
- assertEquals(KeysResponse.url1, action.getUrl().toString());
- assertEquals(KeysResponse.name1, action.getName());
- assertEquals(HttpMethod.valueOf(KeysResponse.method1.toUpperCase()), action.getMethod());
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/KeyDomUnmarshallingTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,97 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.client.Key;
+import org.jboss.tools.deltacloud.client.unmarshal.ActionUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.KeyUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.KeysUnmarshaller;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes.KeyActionResponse;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes.KeyResponse;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.KeyResponseFakes.KeysResponse;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class KeyDomUnmarshallingTest {
+
+ @Test
+ public void keyActionMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
+ Action<Key> keyAction = new Action<Key>();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(KeyActionResponse.keyActionResponse.getBytes());
+ new ActionUnmarshaller<Key>().unmarshall(inputStream, keyAction);
+ assertNotNull(keyAction);
+ assertEquals(KeyActionResponse.name, keyAction.getName());
+ assertEquals(KeyActionResponse.url, keyAction.getUrl().toString());
+ assertEquals(KeyActionResponse.method.toUpperCase(), keyAction.getMethod().toString().toUpperCase());
+ }
+
+ @Test
+ public void keyMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
+ Key key = new Key();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(KeyResponse.keyResponse.getBytes());
+ new KeyUnmarshaller().unmarshall(inputStream, key);
+ assertNotNull(key);
+ assertEquals(KeyResponseFakes.KeyResponse.id, key.getId());
+ assertEquals(KeyResponse.fingerprint, key.getFingerprint());
+ assertEquals(new URL(KeyResponse.url), key.getUrl());
+ assertEquals(KeyResponse.pem, key.getPem());
+ assertEquals(1, key.getActions().size());
+ Action<Key> action = key.getActions().get(0);
+ assertNotNull(action);
+ assertEquals(KeyResponse.url, action.getUrl().toString());
+ assertEquals(KeyResponse.name, action.getName());
+ assertEquals(HttpMethod.valueOf(KeyResponse.method.toUpperCase()), action.getMethod());
+ }
+
+ @Test
+ public void keysMayBeUnmarshalled() throws MalformedURLException, JAXBException, DeltaCloudClientException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(KeysResponse.keysResponse.getBytes());
+ List<Key> keys = new ArrayList<Key>();
+ new KeysUnmarshaller().unmarshall(inputStream, keys);
+ assertEquals(2, keys.size());
+ Key key = keys.get(0);
+ assertEquals(KeysResponse.id1, key.getId());
+ assertEquals(KeysResponse.fingerprint1, key.getFingerprint());
+ assertEquals(new URL(KeysResponse.url1), key.getUrl());
+ assertEquals(KeysResponse.pem1, key.getPem());
+ assertEquals(1, key.getActions().size());
+ Action<Key> action = key.getActions().get(0);
+ assertNotNull(action);
+ assertEquals(KeysResponse.url1, action.getUrl().toString());
+ assertEquals(KeysResponse.name1, action.getName());
+ assertEquals(HttpMethod.valueOf(KeysResponse.method1.toUpperCase()), action.getMethod());
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/KeyMockIntegrationTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,164 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.matchers.JUnitMatchers.hasItem;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
-import org.jboss.tools.deltacloud.core.client.Key;
-import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Integration tests for key related operations in delta cloud client.
- *
- * @author Andre Dietisheim
- *
- * @see DeltaCloudClientImpl#createKey(String, String)
- * @see DeltaCloudClientImpl#deleteKey(String)
- */
-public class KeyMockIntegrationTest {
-
- private MockIntegrationTestContext testSetup;
-
- @Before
- public void setUp() throws IOException, DeltaCloudClientException {
- this.testSetup = new MockIntegrationTestContext();
- testSetup.setUp();
- }
-
- @After
- public void tearDown() {
- testSetup.tearDown();
- }
-
- @Test
- public void canCreateKey() throws DeltaCloudClientException {
- String id = "test" + System.currentTimeMillis();
- DeltaCloudClient client = testSetup.getClient();
- try {
- Key key = client.createKey(id);
- assertNotNull(key);
- assertEquals(id, key.getId());
- } finally {
- quietlyDeleteKey(id);
- }
- }
-
- @Test(expected = DeltaCloudClientException.class)
- public void createDuplicateKeyThrowsException() throws DeltaCloudClientException {
- String id = "test" + System.currentTimeMillis();
- DeltaCloudClient client = testSetup.getClient();
- try {
- client.createKey(id);
- client.createKey(id);
- } finally {
- quietlyDeleteKey(id);
- }
- }
-
- /**
- * Checks if a key may be deleted.
- */
- @Test(expected = DeltaCloudNotFoundClientException.class)
- public void canDeleteKey() throws DeltaCloudClientException {
- String id = "test" + System.currentTimeMillis();
- DeltaCloudClient client = testSetup.getClient();
- Key key = client.createKey(id);
- assertNotNull(key);
- assertEquals(id, key.getId());
- key.destroy(client);
- client.listKey(key.getId());
- }
-
- /**
- * checks if the client throws a {@link DeltaCloudNotFoundClientException}
- * if an unknown key is requested.
- *
- * @throws DeltaCloudClientException
- */
- @Test(expected = DeltaCloudNotFoundClientException.class)
- public void listUnknownKeyThrowsException() throws DeltaCloudClientException {
- String id = String.valueOf(System.currentTimeMillis());
- testSetup.getClient().listKey(id);
- }
-
- @Test
- public void canListKey() throws DeltaCloudClientException {
- String id = String.valueOf(System.currentTimeMillis());
- DeltaCloudClient client = testSetup.getClient();
- try {
- Key createdKey = client.createKey(id);
- Key listedKey = client.listKey(id);
- assertEquals(createdKey.getId(), listedKey.getId());
- } finally {
- quietlyDeleteKey(id);
- }
- }
-
- @Test
- public void canListKeys() throws DeltaCloudClientException {
- String id = String.valueOf(System.currentTimeMillis());
- DeltaCloudClient client = testSetup.getClient();
- try {
- final Key createdKey = client.createKey(id);
- List<Key> keys = client.listKeys();
- assertNotNull(keys);
- assertThat(keys, hasItem(new BaseMatcher<Key>() {
-
- @Override
- public boolean matches(Object item) {
- if (item instanceof Key) {
- Key listedKey = (Key) item;
- return
- createdKey.getId().equals(listedKey.getId())
- && createdKey.getFingerprint().equals(listedKey.getFingerprint())
- && createdKey.getPem().equals(listedKey.getPem())
- && createdKey.getUrl().equals(listedKey.getUrl())
- && createdKey.getActions().size() == listedKey.getActions().size();
- }
- return false;
- }
-
- @Override
- public void describeTo(Description description) {
- // TODO Auto-generated method stub
-
- }
- }));
- } finally {
- quietlyDeleteKey(id);
- }
- }
-
- private void quietlyDeleteKey(String id) {
- try {
- DeltaCloudClient client = testSetup.getClient();
- Key key = client.listKey(id);
- key.destroy(client);
- } catch (Exception e) {
- // ignore
- }
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/KeyMockIntegrationTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/KeyMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,172 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.jboss.tools.deltacloud.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.client.Key;
+import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration tests for key related operations in delta cloud client.
+ *
+ * @author Andre Dietisheim
+ *
+ * @see DeltaCloudClientImpl#createKey(String, String)
+ * @see DeltaCloudClientImpl#deleteKey(String)
+ */
+public class KeyMockIntegrationTest {
+
+ private MockIntegrationTestContext testSetup;
+
+ @Before
+ public void setUp() throws IOException, DeltaCloudClientException {
+ this.testSetup = new MockIntegrationTestContext();
+ testSetup.setUp();
+ }
+
+ @After
+ public void tearDown() {
+ testSetup.tearDown();
+ }
+
+ @Test
+ public void canCreateKey() throws DeltaCloudClientException {
+ String id = "test" + System.currentTimeMillis();
+ DeltaCloudClient client = testSetup.getClient();
+ try {
+ Key key = client.createKey(id);
+ assertNotNull(key);
+ assertEquals(id, key.getId());
+ } finally {
+ quietlyDeleteKey(id);
+ }
+ }
+
+ @Test(expected = DeltaCloudClientException.class)
+ public void createDuplicateKeyThrowsException() throws DeltaCloudClientException {
+ String id = "test" + System.currentTimeMillis();
+ DeltaCloudClient client = testSetup.getClient();
+ try {
+ client.createKey(id);
+ client.createKey(id);
+ } finally {
+ quietlyDeleteKey(id);
+ }
+ }
+
+ /**
+ * Checks if a key may be deleted.
+ */
+ @Test(expected = DeltaCloudNotFoundClientException.class)
+ public void canDeleteKey() throws DeltaCloudClientException {
+ String id = "test" + System.currentTimeMillis();
+ DeltaCloudClient client = testSetup.getClient();
+ Key key = client.createKey(id);
+ assertNotNull(key);
+ assertEquals(id, key.getId());
+ key.destroy(client);
+ client.listKey(key.getId());
+ }
+
+ /**
+ * checks if the client throws a {@link DeltaCloudNotFoundClientException}
+ * if an unknown key is requested.
+ *
+ * @throws DeltaCloudClientException
+ */
+ @Test(expected = DeltaCloudNotFoundClientException.class)
+ public void listUnknownKeyThrowsException() throws DeltaCloudClientException {
+ String id = String.valueOf(System.currentTimeMillis());
+ testSetup.getClient().listKey(id);
+ }
+
+ @Test
+ public void canListKey() throws DeltaCloudClientException {
+ String id = String.valueOf(System.currentTimeMillis());
+ DeltaCloudClient client = testSetup.getClient();
+ try {
+ Key createdKey = client.createKey(id);
+ Key listedKey = client.listKey(id);
+ assertEquals(createdKey.getId(), listedKey.getId());
+ } finally {
+ quietlyDeleteKey(id);
+ }
+ }
+
+ @Test
+ public void canListKeys() throws DeltaCloudClientException {
+ String id = String.valueOf(System.currentTimeMillis());
+ DeltaCloudClient client = testSetup.getClient();
+ try {
+ final Key createdKey = client.createKey(id);
+ List<Key> keys = client.listKeys();
+ assertNotNull(keys);
+ assertThat(keys, hasItem(new BaseMatcher<Key>() {
+
+ @Override
+ public boolean matches(Object item) {
+ if (item instanceof Key) {
+ Key listedKey = (Key) item;
+ return
+ createdKey.getId().equals(listedKey.getId())
+ && createdKey.getFingerprint().equals(listedKey.getFingerprint())
+ && createdKey.getPem().equals(listedKey.getPem())
+ && createdKey.getUrl().equals(listedKey.getUrl())
+ && createdKey.getActions().size() == listedKey.getActions().size();
+ }
+ return false;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ // TODO Auto-generated method stub
+
+ }
+ }));
+ } finally {
+ quietlyDeleteKey(id);
+ }
+ }
+
+ private void quietlyDeleteKey(String id) {
+ try {
+ DeltaCloudClient client = testSetup.getClient();
+ Key key = client.listKey(id);
+ key.destroy(client);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ProfileMockIntegrationTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.HardwareProfile;
-import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Integration tests for key related operations in delta cloud client.
- *
- * @author Andre Dietisheim
- *
- * @see DeltaCloudClientImpl#listProfiles()
- * @see DeltaCloudClientImpl#listProfie(String)
- */
-public class ProfileMockIntegrationTest {
-
- private MockIntegrationTestContext testSetup;
-
- @Before
- public void setUp() throws IOException, DeltaCloudClientException {
- this.testSetup = new MockIntegrationTestContext();
- testSetup.setUp();
- }
-
- @After
- public void tearDown() {
- testSetup.tearDown();
- }
-
- @Test
- public void canListProfiles() throws DeltaCloudClientException {
- List<HardwareProfile> hardwareProfiles = testSetup.getClient().listProfiles();
- assertNotNull(hardwareProfiles);
- assertTrue(hardwareProfiles.size() > 0);
- }
-
- @Test
- public void canGetProfile() throws DeltaCloudClientException {
- // get a profile seen in the web UI
- HardwareProfile profile = testSetup.getClient().listProfile("m1-small");
- assertNotNull(profile);
- assertHardWareProfile("i386", "1740.8 MB", "160 GB", "1", profile);
- }
-
- public void assertHardWareProfile(String architecture, String memory, String storage, String cpu, HardwareProfile profile) {
- assertEquals(architecture, profile.getArchitecture());
- assertEquals(memory, profile.getMemory());
- assertEquals(storage, profile.getStorage());
- assertEquals(cpu, profile.getCPU());
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ProfileMockIntegrationTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ProfileMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,80 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.HardwareProfile;
+import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration tests for key related operations in delta cloud client.
+ *
+ * @author Andre Dietisheim
+ *
+ * @see DeltaCloudClientImpl#listProfiles()
+ * @see DeltaCloudClientImpl#listProfie(String)
+ */
+public class ProfileMockIntegrationTest {
+
+ private MockIntegrationTestContext testSetup;
+
+ @Before
+ public void setUp() throws IOException, DeltaCloudClientException {
+ this.testSetup = new MockIntegrationTestContext();
+ testSetup.setUp();
+ }
+
+ @After
+ public void tearDown() {
+ testSetup.tearDown();
+ }
+
+ @Test
+ public void canListProfiles() throws DeltaCloudClientException {
+ List<HardwareProfile> hardwareProfiles = testSetup.getClient().listProfiles();
+ assertNotNull(hardwareProfiles);
+ assertTrue(hardwareProfiles.size() > 0);
+ }
+
+ @Test
+ public void canGetProfile() throws DeltaCloudClientException {
+ // get a profile seen in the web UI
+ HardwareProfile profile = testSetup.getClient().listProfile("m1-small");
+ assertNotNull(profile);
+ assertHardWareProfile("i386", "1740.8 MB", "160 GB", "1", profile);
+ }
+
+ public void assertHardWareProfile(String architecture, String memory, String storage, String cpu, HardwareProfile profile) {
+ assertEquals(architecture, profile.getArchitecture());
+ assertEquals(memory, profile.getMemory());
+ assertEquals(storage, profile.getStorage());
+ assertEquals(cpu, profile.getCPU());
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/RealmDomUnmarshallingTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.Realm;
-import org.jboss.tools.deltacloud.core.client.Realm.RealmState;
-import org.jboss.tools.deltacloud.core.client.unmarshal.RealmUnmarshaller;
-import org.jboss.tools.deltacloud.core.client.unmarshal.RealmsUnmarshaller;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.RealmResponseFakes;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.RealmResponseFakes.RealmsResponse;
-import org.junit.Test;
-
-/**
- * @author André Dietisheim
- */
-public class RealmDomUnmarshallingTest {
-
- @Test
- public void realmMayBeUnmarshalled() throws DeltaCloudClientException {
- Realm realm = new Realm();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmResponseFakes.realmResponse.response.getBytes());
- new RealmUnmarshaller().unmarshall(inputStream, realm);
- assertNotNull(realm);
- assertEquals(RealmResponseFakes.realmResponse.id, realm.getId());
- assertEquals(RealmResponseFakes.realmResponse.name, realm.getName());
- assertEquals(RealmState.valueOf(RealmResponseFakes.realmResponse.state.toUpperCase()), realm.getState());
- assertEquals(RealmResponseFakes.realmResponse.getIntLimit(), realm.getLimit());
- }
-
- @Test
- public void emptyLimitSetsDefaultLimit() throws DeltaCloudClientException {
- Realm realm = new Realm();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmResponseFakes.invalidLimitRealmResponse.response.getBytes());
- new RealmUnmarshaller().unmarshall(inputStream, realm);
- assertNotNull(realm);
- assertEquals(Realm.LIMIT_DEFAULT, realm.getLimit());
- }
-
- @Test
- public void invalidStateSetsUNKNOWNState() throws DeltaCloudClientException {
- Realm realm = new Realm();
- ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmResponseFakes.invalidLimitRealmResponse.response.getBytes());
- new RealmUnmarshaller().unmarshall(inputStream, realm);
- assertNotNull(realm);
- assertEquals(Realm.LIMIT_DEFAULT, realm.getLimit());
- }
-
- @Test
- public void realmsMayBeUnmarshalled() throws DeltaCloudClientException {
- ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmsResponse.response.getBytes());
- List<Realm> realms = new ArrayList<Realm>();
- new RealmsUnmarshaller().unmarshall(inputStream, realms);
- assertEquals(2, realms.size());
-
- Realm realm = realms.get(0);
- assertEquals(RealmsResponse.id1, realm.getId());
- assertEquals(RealmsResponse.name1, realm.getName());
-
- realm = realms.get(1);
- assertEquals(RealmsResponse.id2, realm.getId());
- assertEquals(RealmsResponse.name2, realm.getName());
- }
-
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/RealmDomUnmarshallingTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmDomUnmarshallingTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.Realm;
+import org.jboss.tools.deltacloud.client.Realm.RealmState;
+import org.jboss.tools.deltacloud.client.unmarshal.RealmUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.RealmsUnmarshaller;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.RealmResponseFakes;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.RealmResponseFakes.RealmsResponse;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class RealmDomUnmarshallingTest {
+
+ @Test
+ public void realmMayBeUnmarshalled() throws DeltaCloudClientException {
+ Realm realm = new Realm();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmResponseFakes.realmResponse.response.getBytes());
+ new RealmUnmarshaller().unmarshall(inputStream, realm);
+ assertNotNull(realm);
+ assertEquals(RealmResponseFakes.realmResponse.id, realm.getId());
+ assertEquals(RealmResponseFakes.realmResponse.name, realm.getName());
+ assertEquals(RealmState.valueOf(RealmResponseFakes.realmResponse.state.toUpperCase()), realm.getState());
+ assertEquals(RealmResponseFakes.realmResponse.getIntLimit(), realm.getLimit());
+ }
+
+ @Test
+ public void emptyLimitSetsDefaultLimit() throws DeltaCloudClientException {
+ Realm realm = new Realm();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmResponseFakes.invalidLimitRealmResponse.response.getBytes());
+ new RealmUnmarshaller().unmarshall(inputStream, realm);
+ assertNotNull(realm);
+ assertEquals(Realm.LIMIT_DEFAULT, realm.getLimit());
+ }
+
+ @Test
+ public void invalidStateSetsUNKNOWNState() throws DeltaCloudClientException {
+ Realm realm = new Realm();
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmResponseFakes.invalidLimitRealmResponse.response.getBytes());
+ new RealmUnmarshaller().unmarshall(inputStream, realm);
+ assertNotNull(realm);
+ assertEquals(Realm.LIMIT_DEFAULT, realm.getLimit());
+ }
+
+ @Test
+ public void realmsMayBeUnmarshalled() throws DeltaCloudClientException {
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(RealmsResponse.response.getBytes());
+ List<Realm> realms = new ArrayList<Realm>();
+ new RealmsUnmarshaller().unmarshall(inputStream, realms);
+ assertEquals(2, realms.size());
+
+ Realm realm = realms.get(0);
+ assertEquals(RealmsResponse.id1, realm.getId());
+ assertEquals(RealmsResponse.name1, realm.getName());
+
+ realm = realms.get(1);
+ assertEquals(RealmsResponse.id2, realm.getId());
+ assertEquals(RealmsResponse.name2, realm.getName());
+ }
+
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/RealmMockIntegrationTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.Realm;
-import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Integration tests for key related operations in delta cloud client.
- *
- * @author Andre Dietisheim
- *
- * @see DeltaCloudClientImpl#listRealms()
- * @see DeltaCloudClientImpl#listRealm(String)
- */
-public class RealmMockIntegrationTest {
-
- private MockIntegrationTestContext testSetup;
-
- @Before
- public void setUp() throws IOException, DeltaCloudClientException {
- this.testSetup = new MockIntegrationTestContext();
- testSetup.setUp();
- }
-
- @After
- public void tearDown() {
- testSetup.tearDown();
- }
-
- @Test
- public void canListRealms() throws DeltaCloudClientException {
- List<Realm> realms = testSetup.getClient().listRealms();
- assertNotNull(realms);
- assertTrue(realms.size() > 0);
- }
-
- @Test
- public void canGetProfile() throws DeltaCloudClientException {
- // get a profile seen in the web UI
- Realm realm = testSetup.getClient().listRealms("eu");
- assertNotNull(realm);
- assertRealm("Europe", Realm.RealmState.AVAILABLE, 0, realm);
- }
-
- public void assertRealm(String name, Realm.RealmState state, int limit, Realm realm) {
- assertEquals(name, realm.getName());
- assertEquals(state, realm.getState());
- assertEquals(limit, realm.getLimit());
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/RealmMockIntegrationTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/RealmMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,79 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.Realm;
+import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration tests for key related operations in delta cloud client.
+ *
+ * @author Andre Dietisheim
+ *
+ * @see DeltaCloudClientImpl#listRealms()
+ * @see DeltaCloudClientImpl#listRealm(String)
+ */
+public class RealmMockIntegrationTest {
+
+ private MockIntegrationTestContext testSetup;
+
+ @Before
+ public void setUp() throws IOException, DeltaCloudClientException {
+ this.testSetup = new MockIntegrationTestContext();
+ testSetup.setUp();
+ }
+
+ @After
+ public void tearDown() {
+ testSetup.tearDown();
+ }
+
+ @Test
+ public void canListRealms() throws DeltaCloudClientException {
+ List<Realm> realms = testSetup.getClient().listRealms();
+ assertNotNull(realms);
+ assertTrue(realms.size() > 0);
+ }
+
+ @Test
+ public void canGetProfile() throws DeltaCloudClientException {
+ // get a profile seen in the web UI
+ Realm realm = testSetup.getClient().listRealms("eu");
+ assertNotNull(realm);
+ assertRealm("Europe", Realm.RealmState.AVAILABLE, 0, realm);
+ }
+
+ public void assertRealm(String name, Realm.RealmState state, int limit, Realm realm) {
+ assertEquals(name, realm.getName());
+ assertEquals(state, realm.getState());
+ assertEquals(limit, realm.getLimit());
+ }
+}
Deleted: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ServerTypeMockIntegrationTest.java 2011-05-19 14:57:51 UTC (rev 31383)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.internal.deltacloud.client.test.core.client;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.List;
-
-import org.jboss.tools.deltacloud.core.client.API.Driver;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
-import org.jboss.tools.deltacloud.core.client.HttpMethod;
-import org.jboss.tools.deltacloud.core.client.Image;
-import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest;
-import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
-import org.jboss.tools.internal.deltacloud.client.test.fakes.ServerFake;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Integration tests for {@link DeltaCloudClientImpl#getServerType()}.
- *
- * @author Andre Dietisheim
- *
- * @see DeltaCloudClientImpl#getServerType()
- */
-public class ServerTypeMockIntegrationTest {
-
- private MockIntegrationTestContext testSetup;
-
- @Before
- public void setUp() throws IOException, DeltaCloudClientException {
- this.testSetup = new MockIntegrationTestContext();
- testSetup.setUp();
- }
-
- @After
- public void tearDown() {
- testSetup.tearDown();
- }
-
- @Test
- public void recognizesDeltaCloud() throws IOException {
- assertEquals(Driver.MOCK, testSetup.getClient().getServerType());
- }
-
- /**
- *
- * #getServerType reports {@link DeltaCloudClient.DeltaCloudType#UNKNOWN) if it queries a fake server that responds with a unknown answer.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @throws DeltaCloudClientException
- */
- @Test
- public void reportsUnknownUrl() throws IOException, DeltaCloudClientException {
- ServerFake serverFake =
- new ServerFake(
- new URL(MockIntegrationTestContext.SERVERFAKE_URL).getPort(),
- "<dummy></dummy>");
- serverFake.start();
- try {
- assertEquals(
- Driver.UNKNOWN,
- new DeltaCloudClientImpl(
- MockIntegrationTestContext.SERVERFAKE_URL, MockIntegrationTestContext.DELTACLOUD_USER,
- MockIntegrationTestContext.DELTACLOUD_PASSWORD).getServerType());
- } finally {
- serverFake.stop();
- }
- }
-
- @Test(expected = DeltaCloudClientException.class)
- public void listImages_cannotListIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
- DeltaCloudClientImpl client = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser",
- "badPassword");
- client.listImages();
- }
-
- @Test
- public void throwsDeltaCloudClientExceptionOnUnknownResource() {
- try {
- DeltaCloudClientImpl errorClient = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL) {
- @Override
- public List<Image> listImages() throws DeltaCloudClientException {
- request(new DeltaCloudRequest() {
-
- @Override
- public URL getUrl() throws MalformedURLException {
- return new URL(MockIntegrationTestContext.DELTACLOUD_URL + "/DUMMY");
- }
-
- @Override
- public HttpMethod getHttpMethod() {
- return HttpMethod.GET;
- }
-
- @Override
- public String getUrlString() {
- return null;
- }
- }
- );
- return Collections.emptyList();
- }
- };
- errorClient.listImages();
- fail("no exception catched");
- } catch (Exception e) {
- assertEquals(DeltaCloudNotFoundClientException.class, e.getClass());
- }
- }
-}
Copied: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java (from rev 31412, trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/core/client/ServerTypeMockIntegrationTest.java)
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java (rev 0)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/client/ServerTypeMockIntegrationTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -0,0 +1,136 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.API.Driver;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.client.Image;
+import org.jboss.tools.deltacloud.client.request.DeltaCloudRequest;
+import org.jboss.tools.internal.deltacloud.client.test.context.MockIntegrationTestContext;
+import org.jboss.tools.internal.deltacloud.client.test.fakes.ServerFake;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration tests for {@link DeltaCloudClientImpl#getServerType()}.
+ *
+ * @author Andre Dietisheim
+ *
+ * @see DeltaCloudClientImpl#getServerType()
+ */
+public class ServerTypeMockIntegrationTest {
+
+ private MockIntegrationTestContext testSetup;
+
+ @Before
+ public void setUp() throws IOException, DeltaCloudClientException {
+ this.testSetup = new MockIntegrationTestContext();
+ testSetup.setUp();
+ }
+
+ @After
+ public void tearDown() {
+ testSetup.tearDown();
+ }
+
+ @Test
+ public void recognizesDeltaCloud() throws IOException {
+ assertEquals(Driver.MOCK, testSetup.getClient().getServerType());
+ }
+
+ /**
+ *
+ * #getServerType reports {@link DeltaCloudClient.DeltaCloudType#UNKNOWN) if it queries a fake server that responds with a unknown answer.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ * @throws DeltaCloudClientException
+ */
+ @Test
+ public void reportsUnknownUrl() throws IOException, DeltaCloudClientException {
+ ServerFake serverFake =
+ new ServerFake(
+ new URL(MockIntegrationTestContext.SERVERFAKE_URL).getPort(),
+ "<dummy></dummy>");
+ serverFake.start();
+ try {
+ assertEquals(
+ Driver.UNKNOWN,
+ new DeltaCloudClientImpl(
+ MockIntegrationTestContext.SERVERFAKE_URL, MockIntegrationTestContext.DELTACLOUD_USER,
+ MockIntegrationTestContext.DELTACLOUD_PASSWORD).getServerType());
+ } finally {
+ serverFake.stop();
+ }
+ }
+
+ @Test(expected = DeltaCloudClientException.class)
+ public void listImages_cannotListIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
+ DeltaCloudClientImpl client = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser",
+ "badPassword");
+ client.listImages();
+ }
+
+ @Test
+ public void throwsDeltaCloudClientExceptionOnUnknownResource() {
+ try {
+ DeltaCloudClientImpl errorClient = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL) {
+ @Override
+ public List<Image> listImages() throws DeltaCloudClientException {
+ request(new DeltaCloudRequest() {
+
+ @Override
+ public URL getUrl() throws MalformedURLException {
+ return new URL(MockIntegrationTestContext.DELTACLOUD_URL + "/DUMMY");
+ }
+
+ @Override
+ public HttpMethod getHttpMethod() {
+ return HttpMethod.GET;
+ }
+
+ @Override
+ public String getUrlString() {
+ return null;
+ }
+ }
+ );
+ return Collections.emptyList();
+ }
+ };
+ errorClient.listImages();
+ fail("no exception catched");
+ } catch (Exception e) {
+ assertEquals(DeltaCloudNotFoundClientException.class, e.getClass());
+ }
+ }
+}
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/context/MockIntegrationTestContext.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/context/MockIntegrationTestContext.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/context/MockIntegrationTestContext.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.context;
import static org.junit.Assert.assertNotNull;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/APIResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/APIResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/APIResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
/**
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/HardwareProfileResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/HardwareProfileResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/HardwareProfileResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
import org.jboss.tools.deltacloud.client.Property;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ImageResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ImageResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ImageResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/InstanceResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/InstanceResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/InstanceResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
import org.jboss.tools.deltacloud.client.StateAware.State;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/KeyResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/KeyResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/KeyResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
/**
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/RealmResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/RealmResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/RealmResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
import org.jboss.tools.deltacloud.client.Realm.RealmState;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerFake.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerFake.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerFake.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
import java.io.IOException;
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerResponseFakes.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerResponseFakes.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/test/fakes/ServerResponseFakes.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.test.fakes;
/**
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/utils/test/UrlBuilderTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/utils/test/UrlBuilderTest.java 2011-05-22 19:49:05 UTC (rev 31419)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.client.test/src/org/jboss/tools/internal/deltacloud/client/utils/test/UrlBuilderTest.java 2011-05-23 07:28:29 UTC (rev 31420)
@@ -1,13 +1,21 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you 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.jboss.tools.internal.deltacloud.client.utils.test;
import static org.junit.Assert.assertEquals;
13 years, 1 month
JBoss Tools SVN: r31419 - trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-05-22 15:49:05 -0400 (Sun, 22 May 2011)
New Revision: 31419
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/
Log:
ignoring /target folder
Property changes on: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test
___________________________________________________________________
Added: svn:ignore
+ target
13 years, 1 month
JBoss Tools SVN: r31418 - trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-05-22 15:46:30 -0400 (Sun, 22 May 2011)
New Revision: 31418
Modified:
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/build.properties
Log:
Fixing duplicate jaxrs-api jar: /lib folder was removed
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/build.properties
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/build.properties 2011-05-22 19:44:07 UTC (rev 31417)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/build.properties 2011-05-22 19:46:30 UTC (rev 31418)
@@ -1,6 +1,5 @@
source.. = src/,\
resources/
output.. = bin/
-bin.includes = META-INF/,\
- lib/
+bin.includes = META-INF/
jre.compilation.profile = JavaSE-1.6
13 years, 1 month
JBoss Tools SVN: r31417 - in trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core: metamodel and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-05-22 15:44:07 -0400 (Sun, 22 May 2011)
New Revision: 31417
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
Log:
Initial support for javax.ws.rs.core.Application subclass annotated with @ApplicationPath
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java 2011-05-22 16:04:56 UTC (rev 31416)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JaxrsMetamodelBuilder.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -63,7 +63,7 @@
public static final QualifiedName JAXRS_ELEMENT_CHANGE_LISTENER_NAME = new QualifiedName(
JBossJaxrsCorePlugin.PLUGIN_ID, "jaxrsPostReconcileListener");
- private List<IJavaElementDelta> changeHints = new ArrayList<IJavaElementDelta>();
+ private final List<IJavaElementDelta> changeHints = new ArrayList<IJavaElementDelta>();
// TODO : add support for cancellation
// TODO : report build failed
@@ -178,7 +178,7 @@
metamodel.reset();
}
// FIXME : determine correct service base URI
- metamodel.setServiceURI("/*");
+ metamodel.setServiceUri("/*");
metamodel.addElements(javaProject, monitor);
metamodel.validate(monitor);
long endTime = new Date().getTime();
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+
+/**
+ * The optional '@Application' annotation, used to designate the base context
+ * URI of the root resources.
+ *
+ *
+ * @author xcoulon
+ *
+ */
+public class Application extends BaseElement<IType> {
+
+ /**
+ * Internal 'HTTPMethod' element builder.
+ *
+ * @author xcoulon
+ *
+ */
+ public static class Builder {
+
+ private final Metamodel metamodel;
+ private final IType javaType;
+
+ /**
+ * Mandatory attributes of the enclosing 'HTTPMethod' element.
+ *
+ * @param javaType
+ * @param metamodel
+ */
+ public Builder(final IType javaType, final Metamodel metamodel) {
+ this.javaType = javaType;
+ this.metamodel = metamodel;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public Application build(IProgressMonitor progressMonitor) throws CoreException {
+ Application httpMethod = new Application(this);
+ httpMethod.merge(javaType, progressMonitor);
+ return httpMethod;
+ }
+ }
+
+ /**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ private Application(Builder builder) {
+ super(builder.javaType, builder.metamodel);
+ }
+
+ @Override
+ public void merge(IType element, IProgressMonitor progressMonitor) throws CoreException {
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+ String appPath = (String) JdtUtils.resolveAnnotationAttributeValue(getJavaElement(), compilationUnit,
+ javax.ws.rs.ApplicationPath.class, "value");
+ if (appPath != null) {
+ getMetamodel().setServiceUri(appPath);
+ }
+ }
+
+ @Override
+ public void validate(IProgressMonitor progressMonitor) throws CoreException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumType getKind() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Application.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -0,0 +1,60 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
+import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+
+/**
+ * Container for all elements extending the
+ * <code>javax.ws.rs.core.Application</code>. There should be only one per
+ * application, so this container will be useful when it comes to detecting
+ * "duplicate" classes.
+ *
+ * @author xcoulon
+ *
+ */
+public class Applications extends BaseElementContainer<Application> {
+
+ /**
+ * Default constructor
+ *
+ * @param metamodel
+ */
+ public Applications(Metamodel metamodel) {
+ super(metamodel);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws InvalidModelElementException
+ */
+ @Override
+ public void addFrom(IJavaElement scope, IProgressMonitor progressMonitor) throws CoreException {
+ IType applicationType = JdtUtils.resolveType(javax.ws.rs.core.Application.class.getName(),
+ metamodel.getJavaProject(), progressMonitor);
+ ITypeHierarchy applicationTypeHierarchy = JdtUtils
+ .resolveTypeHierarchy(applicationType, false, progressMonitor);
+ IType[] subtypes = applicationTypeHierarchy.getAllSubtypes(applicationType);
+ if (subtypes.length > 1) {
+ List<String> s = new ArrayList<String>();
+ for (IType t : subtypes) {
+ s.add(t.getElementName());
+ }
+ Logger.error("Multiple subclasses of '" + Application.class.getName()
+ + " were found, but only one should be defined: " + s);
+ }
+ for (IType t : subtypes) {
+ Application application = new Application.Builder(t, metamodel).build(progressMonitor);
+ elements.put(t.getElementName(), application);
+ }
+
+ }
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Applications.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-05-22 16:04:56 UTC (rev 31416)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -36,8 +36,11 @@
/**
* Adding elements from the given scope.
*
+ * @throws InvalidModelElementException
+ *
*/
- public abstract void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException;
+ public abstract void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor)
+ throws CoreException, InvalidModelElementException;
/**
* Remove an element from the container given its underlying (eclipse)
@@ -135,4 +138,9 @@
public void reset() {
this.elements.clear();
}
+
+ @Override
+ public String toString() {
+ return elements.toString();
+ }
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-05-22 16:04:56 UTC (rev 31416)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -15,6 +15,11 @@
import java.util.Arrays;
import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -43,9 +48,6 @@
*/
public class Metamodel {
- /** the number of steps to add or merge the metamodel. */
- private static final int TOTAL_STEPS = 3;
-
/**
* The qualified name of the metamodel when stored in the project session
* properties.
@@ -53,11 +55,11 @@
private static final QualifiedName METAMODEL_QUALIFIED_NAME = new QualifiedName(JBossJaxrsCorePlugin.PLUGIN_ID,
"metamodel");
- /** The enclosing Project. */
- private final IProject project;
+ /** The enclosing JavaProject. */
+ private final IJavaProject javaProject;
/** The Service URI. Default is "/" */
- private String serviceURI = "/";
+ private String serviceUri = "/";
/**
* List of JAX-RS annotation qualified names, including both core
@@ -67,6 +69,12 @@
private final List<String> jaxrsAnnotationNames = new ArrayList<String>();
/**
+ * All the subclasses of <code>javax.ws.rs.core.Application</code>, although
+ * there should be only one.
+ */
+ private final Applications applications;
+
+ /**
* All the resources (both rootresources and subresources) available in the
* service , indexed by their associated java type fully qualified name.
*/
@@ -82,34 +90,6 @@
/** The HTTP ResourceMethod elements container. */
private final HTTPMethods httpMethods;
- /** The <code>javax.ws.rs.ext.Provider</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PROVIDER = "javax.ws.rs.ext.Provider";
-
- /** The <code>@Produces</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PRODUCES = "javax.ws.rs.Produces";
-
- /** The <code>@Path</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PATH = "javax.ws.rs.Path";
-
- /** The <code>@HttpMethod</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_HTTP_METHOD = "javax.ws.rs.HttpMethod";
-
- /** The <code>@QueryParam</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_QUERY_PARAM = "javax.ws.rs.QueryParam";
-
- /** The <code>@PathParam</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_PATH_PARAM = "javax.ws.rs.PathParam";
-
- /** The <code>@Consumes</code> annotation qualified name. */
- @Deprecated
- public static final String ANNOTATION_CONSUMES = "javax.ws.rs.Consumes";
-
/**
* Full constructor.
*
@@ -119,17 +99,24 @@
* in case of underlying exception
*/
public Metamodel(final IJavaProject javaProject) throws CoreException {
- this.project = javaProject.getProject();
+ this.javaProject = javaProject;
+ applications = new Applications(this);
providers = new Providers(javaProject, this);
resources = new Resources(this);
httpMethods = new HTTPMethods(this);
- jaxrsAnnotationNames.addAll(Arrays.asList(new String[] { Metamodel.ANNOTATION_PROVIDER,
- Metamodel.ANNOTATION_CONSUMES, Metamodel.ANNOTATION_PRODUCES, Metamodel.ANNOTATION_PATH,
- Metamodel.ANNOTATION_HTTP_METHOD }));
- project.setSessionProperty(METAMODEL_QUALIFIED_NAME, this);
+ jaxrsAnnotationNames.addAll(Arrays.asList(new String[] { Provider.class.getName(), Consumes.class.getName(),
+ Produces.class.getName(), Path.class.getName(), HttpMethod.class.getName() }));
+ javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, this);
}
/**
+ * @return the javaProject
+ */
+ public IJavaProject getJavaProject() {
+ return javaProject;
+ }
+
+ /**
* Accessor to the metamodel from the given project's session properties.
*
* @param project
@@ -148,8 +135,8 @@
* in case of underlying exception
*/
public final void remove() throws CoreException {
- Logger.info("JAX-RS Metamodel removed for project " + project.getName());
- project.setSessionProperty(METAMODEL_QUALIFIED_NAME, null);
+ Logger.info("JAX-RS Metamodel removed for project " + javaProject.getElementName());
+ javaProject.getProject().setSessionProperty(METAMODEL_QUALIFIED_NAME, null);
}
/**
@@ -174,24 +161,24 @@
}
/**
- * @return the serviceURI
+ * @return the serviceUri
*/
- public final String getServiceURI() {
- return serviceURI;
+ public final String getServiceUri() {
+ return serviceUri;
}
/**
* Sets the Base URI for the URI mapping templates.
*
* @param uri
- * the serviceURI to set
+ * the serviceUri to set
*/
- public final void setServiceURI(final String uri) {
+ public final void setServiceUri(final String uri) {
// remove trailing "*" character, if present.
if (uri.endsWith("*")) {
- this.serviceURI = uri.substring(0, uri.length() - 1);
+ this.serviceUri = uri.substring(0, uri.length() - 1);
} else {
- this.serviceURI = uri;
+ this.serviceUri = uri;
}
}
@@ -204,12 +191,14 @@
* the progress monitor
* @throws CoreException
* in case of underlying exception
+ * @throws InvalidModelElementException
*/
public final void addElements(final IJavaElement scope, final IProgressMonitor progressMonitor)
throws CoreException {
try {
-
- progressMonitor.beginTask("Computing JAX-RS metamodel", TOTAL_STEPS);
+ progressMonitor.beginTask("Computing JAX-RS metamodel", 4);
+ applications.addFrom(scope, progressMonitor);
+ progressMonitor.worked(1);
httpMethods.addFrom(scope, progressMonitor);
progressMonitor.worked(1);
providers.addFrom(scope, new SubProgressMonitor(progressMonitor, 1,
@@ -234,7 +223,9 @@
*/
public final void remove(final IResource resource, final IProgressMonitor progressMonitor) {
try {
- progressMonitor.beginTask("Computing JAX-RS metamodel", TOTAL_STEPS);
+ progressMonitor.beginTask("Computing JAX-RS metamodel", 4);
+ applications.removeElement(resource, progressMonitor);
+ progressMonitor.worked(1);
httpMethods.removeElement(resource, progressMonitor);
progressMonitor.worked(1);
resources.removeElement(resource, progressMonitor);
@@ -314,6 +305,7 @@
* the progress monitor
* @throws CoreException
* in case of underlying exception
+ * @throws InvalidModelElementException
*/
public final void applyDelta(final IResourceDelta delta, final IProgressMonitor progressMonitor)
throws CoreException {
@@ -353,6 +345,7 @@
* the progress monitor
* @throws CoreException
* in case of underlying exception
+ * @throws InvalidModelElementException
*/
protected final void mergeElement(final ICompilationUnit compilationUnit, final IProgressMonitor progressMonitor)
throws CoreException {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-05-22 16:04:56 UTC (rev 31416)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -46,6 +46,7 @@
* @param metamodel
* @throws CoreException
*/
+ // TODO : use the Builder pattern here ?
public Providers(final IJavaProject javaProject, final Metamodel metamodel) throws CoreException {
super(metamodel);
providerInterfaces = new HashMap<EnumProviderKind, IType>();
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-05-22 16:04:56 UTC (rev 31416)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -69,7 +69,8 @@
final IProgressMonitor progressMonitor) throws CoreException {
Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings = new HashMap<ResolvedUriMapping, Stack<ResourceMethod>>();
for (Resource resource : getRootResources()) {
- resolveResourcesUriMappings(resource, "/*", uriMappings, new Stack<ResourceMethod>(), progressMonitor);
+ resolveResourcesUriMappings(resource, metamodel.getServiceUri(), uriMappings, new Stack<ResourceMethod>(),
+ progressMonitor);
}
return uriMappings;
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-05-22 16:04:56 UTC (rev 31416)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-05-22 19:44:07 UTC (rev 31417)
@@ -386,7 +386,8 @@
* @throws CoreException
* the underlying CoreException thrown by the manipulated JDT
* APIs
- *
+ * @deprecated use resolveAnnotationAttributeValue(IMember, CompilationUnit,
+ * Class<?>, String) instead.
*/
@Deprecated
public static Object resolveAnnotationAttributeValue(final IAnnotationBinding annotationBinding,
13 years, 1 month
JBoss Tools SVN: r31416 - in trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core: src/org/jboss/tools/ws/jaxrs/core/internal/builder and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-05-22 12:04:56 -0400 (Sun, 22 May 2011)
New Revision: 31416
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/lib/jaxrs-api.jar
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
Log:
Refactoring pieces of the metamodel classes and JdtUtils API + Fixing incomplete jaxrs-api jar
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/lib/jaxrs-api.jar
===================================================================
(Binary files differ)
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/builder/JAXRSAnnotationsScanner.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -28,7 +28,6 @@
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
@@ -123,7 +122,7 @@
public static List<IType> findHTTPMethodTypes(final IJavaElement scope, final IProgressMonitor progressMonitor)
throws CoreException {
IJavaSearchScope searchScope = null;
- if(scope instanceof IJavaProject) {
+ if (scope instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) scope;
searchScope = SearchEngine.createJavaSearchScope(javaProject.getPackageFragmentRoots());
} else {
@@ -243,14 +242,11 @@
*/
public static List<String> resolveMediaTypeCapabilities(final IMember annotatedMember,
final CompilationUnit compilationUnit, final Class<?> annotationClass) throws CoreException {
- IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(annotatedMember, compilationUnit,
- annotationClass);
- Object capabilities = JdtUtils.resolveAnnotationAttributeValue(annotationBinding, "value");
+ Object capabilities = JdtUtils.resolveAnnotationAttributeValue(annotatedMember, compilationUnit,
+ annotationClass, "value");
return asList(capabilities);
}
-
-
/**
* Converts the type signature to a human-readable literal.
*
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElement.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -29,6 +29,8 @@
/** The functional type of the JAX-RS Element. */
public enum EnumType {
+ /** An application */
+ APPLICATION,
/** A root resource. */
ROOT_RESOURCE,
/** A subresource. */
@@ -61,7 +63,7 @@
}
/** The current instance state. */
- private EnumState state = EnumState.UNKNOWN;
+ EnumState state = EnumState.UNKNOWN;
/** The associated metamodel. */
private final Metamodel metamodel;
@@ -79,9 +81,10 @@
* the associated metamodel
* @param element
* the underlying java element
+ * @throws InvalidModelElementException
*/
- public BaseElement(final Metamodel model, final T element) {
- this.metamodel = model;
+ public BaseElement(final T element, final Metamodel metamodel) {
+ this.metamodel = metamodel;
this.javaElement = element;
}
@@ -93,7 +96,8 @@
}
/**
- * @param javaElement the javaElement to set
+ * @param javaElement
+ * the javaElement to set
*/
public void setJavaElement(T javaElement) {
this.javaElement = javaElement;
@@ -124,31 +128,20 @@
/**
* Returns the CompilationUnit (AST3/DOM) of the given java element.
- * @param element the java element
- * @param progressMonitor the progress monitor
+ *
+ * @param element
+ * the java element
+ * @param progressMonitor
+ * the progress monitor
* @return the compilation unit or null
- * @throws JavaModelException in case of underlying exception
+ * @throws JavaModelException
+ * in case of underlying exception
*/
- final CompilationUnit getCompilationUnit(final T element, final IProgressMonitor progressMonitor)
- throws JavaModelException {
- return JdtUtils.parse(element, progressMonitor);
+ final CompilationUnit getCompilationUnit(final IProgressMonitor progressMonitor) throws JavaModelException {
+ return JdtUtils.parse(javaElement, progressMonitor);
}
/**
- * @return the state
- */
- public final EnumState getState() {
- return state;
- }
-
- /**
- * @param s the state to set
- */
- public final void setState(final EnumState s) {
- this.state = s;
- }
-
- /**
* @return the metamodel
*/
public final Metamodel getMetamodel() {
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -0,0 +1,138 @@
+package org.jboss.tools.ws.jaxrs.core.metamodel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+
+public abstract class BaseElementContainer<T extends BaseElement<?>> implements Iterable<Entry<String, T>> {
+
+ /** the elements of the container. */
+ final Map<String, T> elements = new HashMap<String, T>();
+
+ /** the enclosing metamodel. */
+ final Metamodel metamodel;
+
+ /**
+ * Full constructor.
+ *
+ * @param m
+ * the enclosing metamodel
+ */
+ public BaseElementContainer(final Metamodel m) {
+ this.metamodel = m;
+ }
+
+ /**
+ * Adding elements from the given scope.
+ *
+ */
+ public abstract void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException;
+
+ /**
+ * Remove an element from the container given its underlying (eclipse)
+ * resource
+ *
+ * @param removedResource
+ * @param progressMonitor
+ */
+ public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
+ for (Iterator<T> iterator = elements.values().iterator(); iterator.hasNext();) {
+ T element = iterator.next();
+ if (removedResource.equals(element.getJavaElement().getResource())) {
+ iterator.remove();
+ return;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#contains(org
+ * .eclipse.jdt.core.IType)
+ */
+ public final boolean contains(final IType type) {
+ return elements.containsKey(type.getFullyQualifiedName());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getByType(org
+ * .eclipse.jdt.core.IType)
+ */
+ public final T getByType(final IType type) {
+ return elements.get(type.getFullyQualifiedName());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getByTypeName
+ * (java.lang.String)
+ */
+ public final T getByTypeName(final String typeName) {
+ return elements.get(typeName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getAll()
+ */
+ public final List<T> getAll() {
+ return Collections.unmodifiableList(new ArrayList<T>(elements.values()));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#getTypeNames()
+ */
+ public final Set<String> getTypeNames() {
+ return elements.keySet();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#size()
+ */
+ public final int size() {
+ return elements.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#iterator()
+ */
+ @Override
+ public final Iterator<Entry<String, T>> iterator() {
+ return elements.entrySet().iterator();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#reset()
+ */
+ public void reset() {
+ this.elements.clear();
+ }
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/BaseElementContainer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethod.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -17,7 +17,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.internal.core.BinaryType;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
@@ -97,27 +96,51 @@
}
/**
- * Full constructor.
+ * Internal 'HTTPMethod' element builder.
*
- * @param javaType
- * the underlying java type
- * @param metamodel
- * the associated parent metamodel
- * @param progressMonitor
- * the progress monitor
- * @throws CoreException
- * in case of underlying exception
- * @throws InvalidModelElementException
- * in case of underlying exception
+ * @author xcoulon
+ *
*/
- public HTTPMethod(final IType javaType, final Metamodel metamodel, final IProgressMonitor progressMonitor)
- throws CoreException, InvalidModelElementException {
- super(metamodel, javaType);
- // this.state = EnumState.CREATING;
- merge(javaType, progressMonitor);
- // this.state = EnumState.CREATED;
+ public static class Builder {
+
+ private final Metamodel metamodel;
+ private final IType javaType;
+
+ /**
+ * Mandatory attributes of the enclosing 'HTTPMethod' element.
+ *
+ * @param javaType
+ * @param metamodel
+ */
+ public Builder(final IType javaType, final Metamodel metamodel) {
+ this.javaType = javaType;
+ this.metamodel = metamodel;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public HTTPMethod build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+ HTTPMethod httpMethod = new HTTPMethod(this);
+ httpMethod.merge(javaType, progressMonitor);
+ return httpMethod;
+ }
}
+ /**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ private HTTPMethod(Builder builder) {
+ super(builder.javaType, builder.metamodel);
+ }
+
@Override
public final void merge(final IType javaType, final IProgressMonitor progressMonitor)
throws InvalidModelElementException, CoreException {
@@ -132,19 +155,11 @@
if (!JdtUtils.isTopLevelType(javaType)) {
throw new InvalidModelElementException("Type is not a top-level type");
}
- CompilationUnit compilationUnit = getCompilationUnit(javaType, progressMonitor);
- /*
- * if (state == EnumState.CREATED) { Set<IProblem> problems =
- * JdtUtils.resolveErrors(javaType, compilationUnit); if (problems !=
- * null && problems.size() > 0) { //metamodel.reportErrors(javaType,
- * problems); return; } }
- */
- IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(getJavaElement(), compilationUnit,
- HttpMethod.class);
- if (annotationBinding == null) {
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+ this.httpVerb = (String) JdtUtils.resolveAnnotationAttributeValue(getJavaElement(), compilationUnit,
+ HttpMethod.class, "value");
+ if (this.httpVerb == null) {
throw new InvalidModelElementException("Annotation binding not found : missing 'import' statement ?");
- } else {
- this.httpVerb = (String) JdtUtils.resolveAnnotationAttributeValue(annotationBinding, "value");
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/HTTPMethods.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -11,16 +11,9 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
@@ -34,34 +27,27 @@
* @author xcoulon
*
*/
-public class HTTPMethods implements Iterable<Entry<String, HTTPMethod>> {
+public class HTTPMethods extends BaseElementContainer<HTTPMethod> {
/**
- * The available HTTP Methods including the 5 standard ones (@GET, @POST,
- * etc.) and the application custom extensions (for WebDAV operations
- * support, etc.): annotations annotated with <code>@HTTPMethod</code>. The resourceMethods are
- * indexed by their associated java type fully qualified name.
- */
- private final Map<String, HTTPMethod> httpMethods = new HashMap<String, HTTPMethod>();
-
- /** the enclosing metamodel. */
- private final Metamodel metamodel;
-
- /**
* Full constructor.
- * @param m the enclosing metamodel
+ *
+ * @param m
+ * the enclosing metamodel
*/
public HTTPMethods(final Metamodel m) {
- this.metamodel = m;
+ super(m);
}
- /**
- * Registers all discovered HTTP Methods in the given scope.
+ /*
+ * (non-Javadoc)
*
- * @param scope the scope from which HTTPMethods should be added
- * @param progressMonitor the progress monitor
- * @throws CoreException in case of underlying exception
+ * @see
+ * org.jboss.tools.ws.jaxrs.core.metamodel.IElementContainer#addFrom(org
+ * .eclipse.jdt.core.IJavaElement,
+ * org.eclipse.core.runtime.IProgressMonitor)
*/
+ @Override
public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
try {
progressMonitor.beginTask("HTTP Methods registration", 2);
@@ -73,8 +59,8 @@
for (IType httpMethodType : httpMethodTypes) {
try {
// FIXME : must retrieve java errors somewhere around here
- this.httpMethods.put(httpMethodType.getFullyQualifiedName(), new HTTPMethod(httpMethodType,
- metamodel, progressMonitor));
+ elements.put(httpMethodType.getFullyQualifiedName(), new HTTPMethod.Builder(httpMethodType,
+ metamodel).build(progressMonitor));
} catch (InvalidModelElementException e) {
Logger.warn("Type '" + httpMethodType.getFullyQualifiedName()
+ "' is not a valid JAX-RS HTTP ResourceMethod: " + e.getMessage());
@@ -87,68 +73,14 @@
}
/**
- * Removes the JAX-RS HTTPMethod associated with the given removed resource.
- * @param removedResource the removed/deleted underlying resource
- * @param progressMonitor the progress monitor
- */
- public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
- for (Iterator<HTTPMethod> iterator = httpMethods.values().iterator(); iterator.hasNext();) {
- HTTPMethod element = iterator.next();
- if (removedResource.equals(element.getJavaElement().getResource())) {
- iterator.remove();
- return;
- }
- }
- }
-
- /**
- * Returns true if an HTTPMethod is based on the given java type.
- * @param type the underlying java type
- * @return true of false ;-)
- */
- public final boolean contains(final IType type) {
- return httpMethods.containsKey(type.getFullyQualifiedName());
- }
-
- /**
- * Returns the HTTPMethod based on the given java type.
- * @param type the underlying java type
- * @return the matching HTTPMethod
- */
- public final HTTPMethod getByType(final IType type) {
- return httpMethods.get(type.getFullyQualifiedName());
- }
-
- /**
- * Returns the HTTPMethod based on the given java type.
- * @param typeName the underlying java type fully qualified name
- * @return the matching HTTPMethod
- */
- public final HTTPMethod getByTypeName(final String typeName) {
- return httpMethods.get(typeName);
- }
-
- /**
- * @return the httpMethods
- */
- public final List<HTTPMethod> getAll() {
- return Collections.unmodifiableList(new ArrayList<HTTPMethod>(httpMethods.values()));
- }
-
- /**
- * @return the list of HTTPMethod types
- */
- public final Set<String> getTypeNames() {
- return httpMethods.keySet();
- }
-
- /**
* Returns the HTTPMethod matching the given HTTP verb.
- * @param httpVerb the HTTP verb
+ *
+ * @param httpVerb
+ * the HTTP verb
* @return the httpMethod bound to the given HTTP Verb
*/
public final HTTPMethod getByVerb(final String httpVerb) {
- for (Entry<String, HTTPMethod> entry : httpMethods.entrySet()) {
+ for (Entry<String, HTTPMethod> entry : elements.entrySet()) {
HTTPMethod httpMethod = entry.getValue();
if (httpMethod.getHttpVerb() != null && httpMethod.getHttpVerb().equals(httpVerb)) {
return httpMethod;
@@ -157,23 +89,4 @@
return null;
}
- /**
- * @return the number of HTTP Methods in the metamodel.
- */
- public final Object size() {
- return httpMethods.size();
- }
-
- @Override
- public final Iterator<Entry<String, HTTPMethod>> iterator() {
- return httpMethods.entrySet().iterator();
- }
-
- /**
- * Resets the HTTPMethods list
- */
- public void reset() {
- this.httpMethods.clear();
- }
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Metamodel.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -64,7 +64,7 @@
* annotations (@Path, etc.) and custom annotations (HTTP Methods).
*
*/
- private List<String> jaxrsAnnotationNames = new ArrayList<String>();
+ private final List<String> jaxrsAnnotationNames = new ArrayList<String>();
/**
* All the resources (both rootresources and subresources) available in the
@@ -208,6 +208,7 @@
public final void addElements(final IJavaElement scope, final IProgressMonitor progressMonitor)
throws CoreException {
try {
+
progressMonitor.beginTask("Computing JAX-RS metamodel", TOTAL_STEPS);
httpMethods.addFrom(scope, progressMonitor);
progressMonitor.worked(1);
@@ -278,7 +279,7 @@
private BaseElement<IMethod> findElement(final IMethod method) throws JavaModelException {
Resource resource = resources.getByType((IType) (method.getParent()));
if (resource != null) {
- return resource.getByJavaMethod((IMethod) method);
+ return resource.getByJavaMethod(method);
}
return null;
}
@@ -427,7 +428,7 @@
this.httpMethods.reset();
this.providers.reset();
this.resources.reset();
-
+
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Provider.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -56,20 +56,55 @@
private final Providers container;
/**
- * @param javaType
- * @throws CoreException
- * @throws InvalidModelElementException
+ * Internal 'Provider' element builder.
+ *
+ * @author xcoulon
+ *
*/
- public Provider(final IType javaType, final Metamodel metamodel, final Providers container,
- final IProgressMonitor progressMonitor) throws CoreException, InvalidModelElementException {
- super(metamodel, javaType);
- this.container = container;
- setState(EnumState.CREATING);
- merge(javaType, progressMonitor);
- setState(EnumState.CREATED);
+ public static class Builder {
+
+ private final Metamodel metamodel;
+ private final IType javaType;
+ private final Providers container;
+
+ /**
+ * Mandatory attributes of the enclosing 'Provider' element.
+ *
+ * @param javaType
+ * @param metamodel
+ */
+ public Builder(final IType javaType, final Metamodel metamodel, final Providers container) {
+ this.javaType = javaType;
+ this.metamodel = metamodel;
+ this.container = container;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public Provider build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+ Provider provider = new Provider(this);
+ provider.merge(javaType, progressMonitor);
+ return provider;
+ }
}
/**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ private Provider(Builder builder) {
+ super(builder.javaType, builder.metamodel);
+ this.container = builder.container;
+ }
+
+ /**
* @param javaType
* @throws InvalidModelElementException
* @throws CoreException
@@ -80,13 +115,11 @@
if (!JdtUtils.isTopLevelType(javaType)) {
throw new InvalidModelElementException("Type is not a top-level type");
}
- CompilationUnit compilationUnit = getCompilationUnit(javaType, progressMonitor);
- if (getState() == EnumState.CREATED) {
- Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
- if (problems != null && problems.size() > 0) {
- // metamodel.reportErrors(javaType, problems);
- return;
- }
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+ Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
+ if (problems != null && problems.size() > 0) {
+ // metamodel.reportErrors(javaType, problems);
+ return;
}
IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(javaType, compilationUnit,
javax.ws.rs.ext.Provider.class);
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Providers.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -14,19 +14,15 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
import org.jboss.tools.ws.jaxrs.core.metamodel.Provider.EnumProviderKind;
@@ -38,23 +34,20 @@
* @author xcoulon
*
*/
-public class Providers {
+public class Providers extends BaseElementContainer<Provider> {
- /**
- * The available providers (classes which implement MessageBodyWriter<T>,
- * MessageBodyReader<T> or ExceptionMapper<T>), , indexed by their
- * associated java type fully qualified name
- */
- private final Map<String, Provider> providers = new HashMap<String, Provider>();
-
/** The interfaces that a provider can implement, indexed by kind */
- private Map<EnumProviderKind, IType> providerInterfaces;
+ private final Map<EnumProviderKind, IType> providerInterfaces;
- private final Metamodel metamodel;
-
+ /**
+ * Full constructor
+ *
+ * @param javaProject
+ * @param metamodel
+ * @throws CoreException
+ */
public Providers(final IJavaProject javaProject, final Metamodel metamodel) throws CoreException {
- super();
- this.metamodel = metamodel;
+ super(metamodel);
providerInterfaces = new HashMap<EnumProviderKind, IType>();
providerInterfaces.put(EnumProviderKind.CONSUMER,
JdtUtils.resolveType("javax.ws.rs.ext.MessageBodyReader", javaProject.getJavaProject(), null));
@@ -90,14 +83,14 @@
* implement the interface(s). (Yep, this is the hardest part of the thing,
* but it provides added-value to the end-developper...)
*
- * @param errors
+ * @param scope
+ * the scope from which elements should be added
*
- * @param javaElement
* @param progressMonitor
* @throws CoreException
- * @throws JavaModelException
*/
- public final void addFrom(final IJavaElement scope, final SubProgressMonitor progressMonitor) throws CoreException {
+ @Override
+ public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
progressMonitor.beginTask("Adding providers", 1);
try {
// FIXME : add support for javax.ws.rs.ext.ContextResolver(s) (most
@@ -109,8 +102,8 @@
// exists. Throw an exception in constructor ?
for (IType providerType : providerTypes) {
try {
- providers.put(providerType.getFullyQualifiedName(), new Provider(providerType, metamodel, this,
- progressMonitor));
+ elements.put(providerType.getFullyQualifiedName(), new Provider.Builder(providerType, metamodel,
+ this).build(progressMonitor));
} catch (InvalidModelElementException e) {
Logger.warn("Type '" + providerType.getFullyQualifiedName() + "' is not a valid JAX-RS Provider : "
+ e.getMessage());
@@ -120,24 +113,9 @@
} finally {
progressMonitor.done();
}
-
}
- public final boolean contains(final IType providerType) {
- return providers.containsKey(providerType.getFullyQualifiedName());
- }
-
/**
- * Return the provider implemented by the given type, or null if not found.
- *
- * @param peType
- * @return a provider, or null
- */
- public final Provider getByType(final IType javaType) {
- return providers.get(javaType.getFullyQualifiedName());
- }
-
- /**
* Return the provider for the given parameterized type, or null if not
* found.
*
@@ -147,7 +125,7 @@
* @return a provider, or null
*/
public final Provider getFor(final String type) {
- for (Entry<String, Provider> providerEntry : providers.entrySet()) {
+ for (Entry<String, Provider> providerEntry : elements.entrySet()) {
Provider p = providerEntry.getValue();
for (Entry<EnumProviderKind, IType> kindEntry : p.getProvidedKinds().entrySet()) {
if (type.equals(kindEntry.getValue().getFullyQualifiedName())) {
@@ -168,7 +146,7 @@
* @return a provider, or null
*/
public final Provider getFor(final IType providedType) {
- for (Entry<String, Provider> providerEntry : providers.entrySet()) {
+ for (Entry<String, Provider> providerEntry : elements.entrySet()) {
Provider p = providerEntry.getValue();
for (Entry<EnumProviderKind, IType> kindEntry : p.getProvidedKinds().entrySet()) {
if (providedType.equals(kindEntry.getValue())) {
@@ -208,7 +186,7 @@
private List<Provider> filterProvidersByKind(final EnumProviderKind providerKind) {
List<Provider> matches = new ArrayList<Provider>();
- for (Entry<String, Provider> entry : providers.entrySet()) {
+ for (Entry<String, Provider> entry : elements.entrySet()) {
Provider p = entry.getValue();
if (p.getProvidedKinds().containsKey(providerKind)) {
matches.add(p);
@@ -216,34 +194,4 @@
}
return Collections.unmodifiableList(matches);
}
-
- /**
- * @return the all the providers, no matter which role they have (reader,
- * writer, exception mapper)
- */
- public final List<Provider> getAll() {
- return Collections.unmodifiableList(new ArrayList<Provider>(providers.values()));
- }
-
- public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
- for (Iterator<Provider> iterator = providers.values().iterator(); iterator.hasNext();) {
- Provider element = iterator.next();
- if (removedResource.equals(element.getJavaElement().getResource())) {
- iterator.remove();
- return;
- }
- }
- }
-
- public final Object size() {
- return providers.size();
- }
-
- /**
- * Resets the HTTPMethods list
- */
- public void reset() {
- this.providers.clear();
- }
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResolvedUriMapping.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -14,6 +14,8 @@
import java.util.Iterator;
import java.util.List;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
+
public class ResolvedUriMapping implements Comparable<ResolvedUriMapping> {
private HTTPMethod httpMethod = null;
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resource.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -31,7 +31,6 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
import org.jboss.tools.ws.jaxrs.core.internal.utils.CollectionFilterUtil;
@@ -79,23 +78,51 @@
final Map<String, ResourceMethod> resourceMethods = new HashMap<String, ResourceMethod>();
/**
- * Full constructor
+ * Internal 'Resource' element builder.
*
- * @param javaType
- * @param metamodel
- * @param compilationUnit
- * @param mediaTypeCapabilities
- * @throws CoreException
- * @throws InvalidModelElementException
+ * @author xcoulon
+ *
*/
- public Resource(final IType javaType, final Metamodel metamodel, final IProgressMonitor progressMonitor)
- throws CoreException, InvalidModelElementException {
- super(metamodel, javaType);
- setState(EnumState.CREATING);
- merge(javaType, progressMonitor);
- setState(EnumState.CREATED);
+ public static class Builder {
+
+ private final Metamodel metamodel;
+ private final IType javaType;
+
+ /**
+ * Mandatory attributes of the enclosing 'HTTPMethod' element.
+ *
+ * @param javaType
+ * @param metamodel
+ */
+ public Builder(final IType javaType, final Metamodel metamodel) {
+ this.javaType = javaType;
+ this.metamodel = metamodel;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public Resource build(IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
+ Resource resource = new Resource(this);
+ resource.merge(javaType, progressMonitor);
+ return resource;
+ }
}
+ /**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ private Resource(Builder builder) {
+ super(builder.javaType, builder.metamodel);
+ }
+
public final boolean isRootResource() {
return isRootResource;
}
@@ -114,25 +141,22 @@
if (!JdtUtils.isTopLevelType(javaType)) {
throw new InvalidModelElementException("Type is not a top-level type");
}
- CompilationUnit compilationUnit = getCompilationUnit(javaType, progressMonitor);
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
// TODO : base64.decode()
- if (getState() == EnumState.CREATED) {
- Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
- if (problems != null && problems.size() > 0) {
- // metamodel.reportErrors(javaType, problems);
- return;
- }
+ // if (state == EnumState.CREATED) {
+ Set<IProblem> problems = JdtUtils.resolveErrors(javaType, compilationUnit);
+ if (problems != null && problems.size() > 0) {
+ return;
}
+ // }
// String serviceURI = container.getMetamodel().getServiceURI();
- IAnnotationBinding pathAnnotationBinding = JdtUtils.resolveAnnotationBinding(javaType, compilationUnit,
- Path.class);
- if (pathAnnotationBinding != null) {
+ this.uriPathTemplate = (String) JdtUtils.resolveAnnotationAttributeValue(javaType, compilationUnit, Path.class,
+ "value");
+ if (uriPathTemplate != null) {
isRootResource = true;
- this.uriPathTemplate = (String) JdtUtils.resolveAnnotationAttributeValue(pathAnnotationBinding, "value");
} else {
isRootResource = false;
- this.uriPathTemplate = null;
}
mediaTypeCapabilities.setConsumedMimeTypes(JAXRSAnnotationsScanner.resolveMediaTypeCapabilities(javaType,
@@ -184,8 +208,8 @@
resourceMethod.merge(javaMethod, progressMonitor);
Logger.debug("Updated " + resourceMethod.toString());
} else {
- ResourceMethod resourceMethod = new ResourceMethod(javaMethod, this, getMetamodel(),
- progressMonitor);
+ ResourceMethod resourceMethod = new ResourceMethod.Builder(javaMethod, this, getMetamodel())
+ .build(progressMonitor);
resourceMethods.put(key, resourceMethod);
Logger.debug("Added " + resourceMethod.toString());
}
@@ -262,8 +286,8 @@
return CollectionFilterUtil.filterElementsByKind(resourceMethods.values(), EnumType.SUBRESOURCE_LOCATOR);
}
- public final ResourceMethod getByURIMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment, final String consumes,
- final String produces) {
+ public final ResourceMethod getByURIMapping(final HTTPMethod httpMethod, final String uriPathTemplateFragment,
+ final String consumes, final String produces) {
for (ResourceMethod resourceMethod : resourceMethods.values()) {
if (resourceMethod.getUriMapping().matches(httpMethod, uriPathTemplateFragment, consumes, produces)) {
return resourceMethod;
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethod.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -42,39 +42,75 @@
private IType returnType = null;
/**
- * Constructor
+ * Internal 'Resource' element builder.
*
- * @param javaMethod
- * @param metamodel
- * @param problems
- * @throws CoreException
- * @throws InvalidModelElementException
+ * @author xcoulon
+ *
*/
- public ResourceMethod(final IMethod javaMethod, final Resource parentResource, final Metamodel metamodel,
- final IProgressMonitor progressMonitor) throws InvalidModelElementException, CoreException {
- super(metamodel, javaMethod);
- this.parentResource = parentResource;
- setState(EnumState.CREATING);
- merge(javaMethod, progressMonitor);
- setState(EnumState.CREATED);
+ public static class Builder {
+
+ private final Metamodel metamodel;
+ private final IMethod javaMethod;
+ private final Resource parentResource;
+
+ /**
+ * Mandatory attributes of the enclosing 'ResourceMethod' element.
+ *
+ * @param javaMethod
+ * @param metamodel
+ * @param parentResource
+ */
+ public Builder(final IMethod javaMethod, final Resource parentResource, final Metamodel metamodel) {
+ this.javaMethod = javaMethod;
+ this.metamodel = metamodel;
+ this.parentResource = parentResource;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public ResourceMethod build(IProgressMonitor progressMonitor) throws InvalidModelElementException,
+ CoreException {
+ ResourceMethod resourceMethod = new ResourceMethod(this);
+ resourceMethod.merge(javaMethod, progressMonitor);
+ return resourceMethod;
+ }
}
+ /**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ public ResourceMethod(final Builder builder) throws InvalidModelElementException, CoreException {
+ super(builder.javaMethod, builder.metamodel);
+ this.parentResource = builder.parentResource;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public final void merge(final IMethod javaMethod, final IProgressMonitor progressMonitor)
throws InvalidModelElementException, CoreException {
- CompilationUnit compilationUnit = getCompilationUnit(javaMethod, progressMonitor);
- if (getState() == EnumState.CREATED) {
+ CompilationUnit compilationUnit = getCompilationUnit(progressMonitor);
+ if (state == EnumState.CREATED) {
Set<IProblem> problems = JdtUtils.resolveErrors(javaMethod, compilationUnit);
if (problems != null && problems.size() > 0) {
- // metamodel.reportErrors(javaType, problems);
+ // metamodel.reportErrors(javaMethod, problems);
return;
}
}
IMethodBinding methodBinding = JdtUtils.resolveMethodBinding(javaMethod, compilationUnit);
if (uriMapping == null) {
- this.uriMapping = new UriMapping(javaMethod, compilationUnit, getMetamodel());
+ this.uriMapping = new UriMapping.Builder(javaMethod, getMetamodel()).build(compilationUnit);
} else {
- this.uriMapping.merge(javaMethod, compilationUnit);
+ this.uriMapping.merge(compilationUnit);
}
HTTPMethod httpMethod = uriMapping.getHTTPMethod();
String uriPathTemplateFragment = uriMapping.getUriPathTemplateFragment();
@@ -104,6 +140,7 @@
getUriMapping().validate();
}
+ @Override
public final BaseElement.EnumType getKind() {
return kind;
}
Deleted: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xavier Coulon - Initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.ws.jaxrs.core.metamodel;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-public class ResourceMethodAnnotatedParameter implements Validable, Comparable<ResourceMethodAnnotatedParameter> {
-
- private final String parameterType;
-
- private final String annotationType;
-
- private final String annotationValue;
-
- private final int charStart;
-
- private final int charEnd;
-
- private final int lineNumber;
-
-
- /**
- * Full constructor
- * @param parent
- * @param parameterName
- * @param parameterType
- * @param annotationType
- * @param annotationValue
- * @param charStart
- * @param charEnd
- * @param lineNumber
- */
- public ResourceMethodAnnotatedParameter(String parameterType,
- String annotationType, String annotationValue, int charStart, int charEnd, int lineNumber) {
- super();
- this.parameterType = parameterType;
- this.annotationType = annotationType;
- this.annotationValue = annotationValue;
- this.charStart = charStart;
- this.charEnd = charEnd;
- this.lineNumber = lineNumber;
- }
-
- @Override
- public void validate(IProgressMonitor progressMonitor) throws CoreException {
- // TODO Auto-generated method stub
- }
-
- /**
- * @return the parameterType
- */
- public String getParameterType() {
- return parameterType;
- }
-
- /**
- * @return the annotationType
- */
- public String getAnnotationType() {
- return annotationType;
- }
-
- /**
- * @return the annotationValue
- */
- public String getAnnotationValue() {
- return annotationValue;
- }
-
- /**
- * @return the charStart
- */
- public int getCharStart() {
- return charStart;
- }
-
- /**
- * @return the charEnd
- */
- public int getCharEnd() {
- return charEnd;
- }
-
- /**
- * @return the lineNumber
- */
- public int getLineNumber() {
- return lineNumber;
- }
-
- /**
- * Compares method parameters by their textual location
- * {@inheritDoc}
- * @param otherParam
- * @return
- */
- @Override
- public int compareTo(ResourceMethodAnnotatedParameter otherParam) {
- return getCharStart() - otherParam.getCharStart();
- }
-
-}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/Resources.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -11,10 +11,7 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -23,7 +20,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeHierarchy;
@@ -33,24 +29,44 @@
import org.jboss.tools.ws.jaxrs.core.metamodel.BaseElement.EnumType;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
-public class Resources {
+public class Resources extends BaseElementContainer<Resource> {
- private final Map<String, Resource> resources = new HashMap<String, Resource>();
-
- private final Metamodel metamodel;
-
+ /**
+ * Full constructor
+ *
+ * @param metamodel
+ */
public Resources(final Metamodel metamodel) {
- this.metamodel = metamodel;
+ super(metamodel);
}
+ // FIXME deal with interfaces/implementations
+ @Override
+ public final void addFrom(final IJavaElement scope, final IProgressMonitor progressMonitor) throws CoreException {
+ progressMonitor.beginTask("Adding resources and resourceMethods", 1);
+ HTTPMethods httpMethods = metamodel.getHttpMethods();
+ List<IType> javaTypes = JAXRSAnnotationsScanner.findResources(scope, httpMethods.getTypeNames(),
+ progressMonitor);
+ for (IType javaType : javaTypes) {
+ try {
+ elements.put(javaType.getFullyQualifiedName(),
+ new Resource.Builder(javaType, metamodel).build(progressMonitor));
+ } catch (InvalidModelElementException e) {
+ Logger.warn("Type '" + javaType.getFullyQualifiedName() + "' is not a valid JAX-RS Resource: "
+ + e.getMessage());
+ }
+ }
+ }
+
/**
* Resolve the URI Mappings in the model, given all root resources,
- * subresources , resource resourceMethods , subresource resourceMethods and subresource
- * locators
+ * subresources , resource resourceMethods , subresource resourceMethods and
+ * subresource locators
*
* @throws CoreException
*/
- public final Map<ResolvedUriMapping, Stack<ResourceMethod>> resolveUriMappings(final IProgressMonitor progressMonitor) throws CoreException {
+ public final Map<ResolvedUriMapping, Stack<ResourceMethod>> resolveUriMappings(
+ final IProgressMonitor progressMonitor) throws CoreException {
Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings = new HashMap<ResolvedUriMapping, Stack<ResourceMethod>>();
for (Resource resource : getRootResources()) {
resolveResourcesUriMappings(resource, "/*", uriMappings, new Stack<ResourceMethod>(), progressMonitor);
@@ -68,12 +84,14 @@
private void resolveResourcesUriMappings(final Resource resource, final String uriTemplateFragment,
final Map<ResolvedUriMapping, Stack<ResourceMethod>> uriMappings, final Stack<ResourceMethod> methodsStack,
final IProgressMonitor progressMonitor) throws CoreException {
- // resource resourceMethods and subresources resourceMethods are treated the same way
+ // resource resourceMethods and subresources resourceMethods are treated
+ // the same way
for (ResourceMethod resourceMethod : resource.getAllMethods()) {
String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod);
MediaTypeCapabilities mediaTypeCapabilities = resolveMediaTypeCapabilities(resource, resourceMethod);
UriMapping resourceUriMapping = resourceMethod.getUriMapping();
- ResolvedUriMapping uriMapping = new ResolvedUriMapping(resourceUriMapping.getHTTPMethod(), uriPathTemplate, resourceUriMapping.getQueryParams(), mediaTypeCapabilities);
+ ResolvedUriMapping uriMapping = new ResolvedUriMapping(resourceUriMapping.getHTTPMethod(), uriPathTemplate,
+ resourceUriMapping.getQueryParams(), mediaTypeCapabilities);
@SuppressWarnings("unchecked")
Stack<ResourceMethod> stack = (Stack<ResourceMethod>) methodsStack.clone();
stack.add(resourceMethod);
@@ -84,7 +102,7 @@
for (ResourceMethod resourceMethod : resource.getSubresourceLocators()) {
String uriPathTemplate = resolveURIPathTemplate(uriTemplateFragment, resource, resourceMethod);
IType returnType = resourceMethod.getReturnType();
- if(returnType == null) {
+ if (returnType == null) {
continue;
}
ITypeHierarchy subresourceTypeHierarchy = JdtUtils.resolveTypeHierarchy(returnType, false, progressMonitor);
@@ -101,7 +119,8 @@
}
// FIXME : include method parameters if annotated with @QueryParam
- private static final String resolveURIPathTemplate(final String uriTemplateFragment, final Resource resource, final ResourceMethod resourceMethod) {
+ private static final String resolveURIPathTemplate(final String uriTemplateFragment, final Resource resource,
+ final ResourceMethod resourceMethod) {
StringBuffer uriTemplateBuffer = new StringBuffer(uriTemplateFragment);
String resourceUriPathTemplate = resource.getUriPathTemplate();
String methodUriPathTemplate = resourceMethod.getUriMapping().getUriPathTemplateFragment();
@@ -114,7 +133,8 @@
return uriTemplateBuffer.toString().replaceAll("/\\*", "/").replaceAll("///", "/").replaceAll("//", "/");
}
- private static final MediaTypeCapabilities resolveMediaTypeCapabilities(final Resource resource, final ResourceMethod resourceMethod) {
+ private static final MediaTypeCapabilities resolveMediaTypeCapabilities(final Resource resource,
+ final ResourceMethod resourceMethod) {
MediaTypeCapabilities resourceMediaTypeCapabilities = resource.getMediaTypeCapabilities();
MediaTypeCapabilities methodMediaTypeCapabilities = resourceMethod.getUriMapping().getMediaTypeCapabilities();
MediaTypeCapabilities mediaTypeCapabilities = new MediaTypeCapabilities();
@@ -137,62 +157,19 @@
return mediaTypeCapabilities;
}
- // FIXME deal with interfaces/implementations
- public final void addFrom(final IJavaElement scope, final SubProgressMonitor progressMonitor) throws CoreException {
- progressMonitor.beginTask("Adding resources and resourceMethods", 1);
- HTTPMethods httpMethods = metamodel.getHttpMethods();
- List<IType> javaTypes = JAXRSAnnotationsScanner.findResources(scope, httpMethods.getTypeNames(),
- progressMonitor);
- for (IType javaType : javaTypes) {
- try {
- resources.put(javaType.getFullyQualifiedName(), new Resource(javaType, metamodel, progressMonitor));
- } catch (InvalidModelElementException e) {
- Logger.warn("Type '" + javaType.getFullyQualifiedName() + "' is not a valid JAX-RS Resource: "
- + e.getMessage());
- }
- }
- }
-
- public final void removeElement(final IResource removedResource, final IProgressMonitor progressMonitor) {
- for (Iterator<Resource> iterator = resources.values().iterator(); iterator.hasNext();) {
- Resource r = iterator.next();
- if (removedResource.equals(r.getJavaElement().getResource())) {
- iterator.remove();
- }
- }
- }
-
- public final Resource getByType(final IType type) {
- if(type == null) {
- return null;
- }
- return resources.get(type.getFullyQualifiedName());
- }
-
public Resource getByResource(IResource resource) {
- if(resource == null) {
+ if (resource == null) {
return null;
}
- for(Entry<String, Resource> entry : resources.entrySet()) {
+ for (Entry<String, Resource> entry : elements.entrySet()) {
Resource r = entry.getValue();
- if(resource.equals(r.getJavaElement().getResource())) {
+ if (resource.equals(r.getJavaElement().getResource())) {
return r;
}
}
return null;
}
- public final boolean contains(final IType type) {
- if(type == null) {
- return false;
- }
- return resources.containsKey(type.getFullyQualifiedName());
- }
-
- public final Resource getByTypeName(final String fullyQualifiedName) {
- return resources.get(fullyQualifiedName);
- }
-
/**
* Returns the Root resource for the given Path
*
@@ -200,7 +177,7 @@
* @return
*/
public final Resource getByPath(final String path) {
- for (Entry<String, Resource> entry : resources.entrySet()) {
+ for (Entry<String, Resource> entry : elements.entrySet()) {
Resource resource = entry.getValue();
if (resource.isRootResource() && resource.getUriPathTemplate().endsWith(path)) {
return resource;
@@ -210,24 +187,12 @@
return null;
}
- public final List<Resource> getAll() {
- return Collections.unmodifiableList(new ArrayList<Resource>(resources.values()));
- }
-
public final List<Resource> getRootResources() {
- return CollectionFilterUtil.filterElementsByKind(resources.values(), EnumType.ROOT_RESOURCE);
+ return CollectionFilterUtil.filterElementsByKind(elements.values(), EnumType.ROOT_RESOURCE);
}
public final List<Resource> getSubresources() {
- return CollectionFilterUtil.filterElementsByKind(resources.values(), EnumType.SUBRESOURCE);
+ return CollectionFilterUtil.filterElementsByKind(elements.values(), EnumType.SUBRESOURCE);
}
- /**
- * Resets the HTTPMethods list
- */
- public void reset() {
- this.resources.clear();
- }
-
-
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/UriMapping.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -12,10 +12,7 @@
package org.jboss.tools.ws.jaxrs.core.metamodel;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
@@ -29,13 +26,12 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
-import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
-import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JAXRSAnnotationsScanner;
import org.jboss.tools.ws.jaxrs.core.internal.builder.JaxrsMetamodelBuilder;
import org.jboss.tools.ws.jaxrs.core.internal.utils.ValidationMessages;
import org.jboss.tools.ws.jaxrs.core.utils.JdtUtils;
+import org.jboss.tools.ws.jaxrs.core.utils.ResourceMethodAnnotatedParameter;
public class UriMapping {
@@ -55,46 +51,83 @@
private final Metamodel metamodel;
- public UriMapping(final IMethod javaMethod, final CompilationUnit compilationUnit, final Metamodel metamodel)
- throws CoreException {
- this.javaMethod = javaMethod;
- this.metamodel = metamodel;
- merge(javaMethod, compilationUnit);
+ /**
+ * Internal 'Resource' element builder.
+ *
+ * @author xcoulon
+ *
+ */
+ public static class Builder {
+
+ private final IMethod javaMethod;
+ private final Metamodel metamodel;
+
+ /**
+ * Mandatory attributes of the enclosing 'ResourceMethod' element.
+ *
+ * @param javaMethod
+ * @param metamodel
+ * @param parentResource
+ */
+ public Builder(final IMethod javaMethod, final Metamodel metamodel) {
+ this.javaMethod = javaMethod;
+ this.metamodel = metamodel;
+ }
+
+ /**
+ * Builds and returns the elements. Internally calls the merge() method.
+ *
+ * @param progressMonitor
+ * @return
+ * @throws InvalidModelElementException
+ * @throws CoreException
+ */
+ public UriMapping build(final CompilationUnit compilationUnit) throws InvalidModelElementException,
+ CoreException {
+ UriMapping resourceMethod = new UriMapping(this);
+ resourceMethod.merge(compilationUnit);
+ return resourceMethod;
+ }
}
/**
+ * Full constructor using the inner 'Builder' static class.
+ *
+ * @param builder
+ */
+ private UriMapping(Builder builder) {
+ this.javaMethod = builder.javaMethod;
+ this.metamodel = builder.metamodel;
+ }
+
+ /**
* @param javaMethod
* @param compilationUnit
* @throws JavaModelException
* @throws CoreException
*/
- protected void merge(IMethod javaMethod, CompilationUnit compilationUnit) throws JavaModelException, CoreException {
- IAnnotationBinding pathAnnotationBinding = JdtUtils.resolveAnnotationBinding(javaMethod, compilationUnit,
- Path.class);
- IAnnotationBinding httpMethodAnnotationBinding = null;
+ public void merge(CompilationUnit compilationUnit) throws JavaModelException, CoreException {
+ HTTPMethod httpMethod = null;
for (String httpMethodName : metamodel.getHttpMethods().getTypeNames()) {
- httpMethodAnnotationBinding = JdtUtils
- .resolveAnnotationBinding(javaMethod, compilationUnit, httpMethodName);
+ IAnnotationBinding httpMethodAnnotationBinding = JdtUtils.resolveAnnotationBinding(javaMethod,
+ compilationUnit, httpMethodName);
if (httpMethodAnnotationBinding != null) {
+ // String qualifiedName =
+ // JdtUtils.resolveAnnotationFullyQualifiedName(httpMethodAnnotationBinding);
+ // httpMethod =
+ // metamodel.getHttpMethods().getByTypeName(qualifiedName);
+ httpMethod = metamodel.getHttpMethods().getByTypeName(httpMethodName);
// stop iterating
break;
}
}
// resource method
- HTTPMethod httpMethod = null;
- String uriPathTemplateFragment = null;
- if (httpMethodAnnotationBinding != null) {
- String qualifiedName = JdtUtils.resolveAnnotationFullyQualifiedName(httpMethodAnnotationBinding);
- httpMethod = metamodel.getHttpMethods().getByTypeName(qualifiedName);
- }
- if (pathAnnotationBinding != null) {
- uriPathTemplateFragment = (String) JdtUtils.resolveAnnotationAttributeValue(pathAnnotationBinding, "value");
- }
-
- List<ResourceMethodAnnotatedParameter> pathParams = resolveParameters(javaMethod, compilationUnit,
- PathParam.class);
- List<ResourceMethodAnnotatedParameter> queryParams = resolveParameters(javaMethod, compilationUnit,
- QueryParam.class);
+ String uriPathTemplateFragment = (String) JdtUtils.resolveAnnotationAttributeValue(javaMethod, compilationUnit,
+ Path.class, "value");
+ List<ResourceMethodAnnotatedParameter> pathParams = JdtUtils.resolveMethodParameters(javaMethod,
+ compilationUnit, PathParam.class);
+ List<ResourceMethodAnnotatedParameter> queryParams = JdtUtils.resolveMethodParameters(javaMethod,
+ compilationUnit, QueryParam.class);
setHTTPMethod(httpMethod);
setUriPathTemplateFragment(uriPathTemplateFragment);
setPathParams(pathParams);
@@ -105,57 +138,14 @@
setMediaTypeCapabilities(mediaTypeCapabilities);
}
- private List<ResourceMethodAnnotatedParameter> resolveParameters(IMethod javaMethod,
- CompilationUnit compilationUnit, Class<?> annotationType) throws JavaModelException {
- List<ResourceMethodAnnotatedParameter> parameters = new ArrayList<ResourceMethodAnnotatedParameter>();
- Map<IAnnotationBinding, ITypedRegion> bindings = JdtUtils.resolveMethodParamBindings(javaMethod,
- compilationUnit, annotationType);
- for (Entry<IAnnotationBinding, ITypedRegion> entry : bindings.entrySet()) {
- IAnnotationBinding binding = entry.getKey();
- ITypedRegion region = entry.getValue();
- IMemberValuePairBinding[] allMemberValuePairs = binding.getAllMemberValuePairs();
- IMemberValuePairBinding memberValuePair = allMemberValuePairs[0];
- String annotationValue = (String) memberValuePair.getValue();
- int lineNumber = compilationUnit.getLineNumber(region.getOffset());
- parameters.add(new ResourceMethodAnnotatedParameter(region.getType(), annotationType.getName(),
- annotationValue, region.getOffset(), region.getOffset() + region.getLength(), lineNumber));
- }
- Collections.sort(parameters);
- return parameters;
- }
-
/**
- * Convenient constructor
- *
- * @param httpMethod
- * optional http method
- * @param consumes
- * optional single consumed media type
- * @param produces
- * optional single produced media type
- * @param uriPathTemplateFragment
- * optional URI path template fragment public UriMapping(final
- * HTTPMethod httpMethod, final String uriPathTemplateFragment,
- * final String consumes, final String produces, final Metamodel
- * metamodel) { super(); this.metamodel = metamodel;
- * this.httpMethod = httpMethod; List<String> producedMimeTypes =
- * new ArrayList<String>(); if (produces != null) {
- * producedMimeTypes.add(produces); } List<String>
- * consumedMimeTypes = new ArrayList<String>(); if (consumes !=
- * null) { consumedMimeTypes.add(consumes); }
- * setMediaTypeCapabilities(new
- * MediaTypeCapabilities(consumedMimeTypes, producedMimeTypes));
- * setUriPathTemplateFragment(uriPathTemplateFragment);
- * setQueryParams(new HashMap<String, String>()); }
- */
-
- /**
* Validates the URI Mapping by checking that all
* <code>javax.ws.rs.PathParam</code> annotation values match a parameter in
* the URI Path Template fragment defined by the value of the
* <code>java.ws.rs.Path</code> annotation value.
- * @throws CoreException
*
+ * @throws CoreException
+ *
*/
public void validate() throws CoreException {
if (uriPathTemplateFragment != null) {
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-05-22 16:04:20 UTC (rev 31415)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/JdtUtils.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -17,6 +17,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IResource;
@@ -226,7 +227,7 @@
ITypeBinding[] typeArgBindings = typeBinding.getTypeArguments();
arguments = new ArrayList<IType>(typeArgBindings.length);
for (ITypeBinding typeArgBinding : typeArgBindings) {
- Logger.debug("Resolving Java Element for type argument '" + typeArgBinding.getName() +"'");
+ Logger.debug("Resolving Java Element for type argument '" + typeArgBinding.getName() + "'");
IJavaElement javaElement = typeArgBinding.getJavaElement();
if (javaElement.getElementType() == IJavaElement.TYPE && javaElement.exists()) {
arguments.add((IType) javaElement);
@@ -330,7 +331,6 @@
* @throws JavaModelException
* in case of underlying exception
*/
- // TODO : merge with JdtUtils ?
public static Map<IAnnotationBinding, ITypedRegion> resolveMethodParamBindings(final IMethod javaMethod,
CompilationUnit compilationUnit, final Class<?> annotationTypeFilter) throws JavaModelException {
MemberAnnotationBindingsVisitor visitor = new MemberAnnotationBindingsVisitor(javaMethod,
@@ -386,7 +386,9 @@
* @throws CoreException
* the underlying CoreException thrown by the manipulated JDT
* APIs
+ *
*/
+ @Deprecated
public static Object resolveAnnotationAttributeValue(final IAnnotationBinding annotationBinding,
final String attributeName) throws CoreException {
if (annotationBinding != null) {
@@ -400,6 +402,36 @@
}
/**
+ * Returns the value set for the given attribute from the given annotation
+ * binding.
+ *
+ * @param annotationBinding
+ * the annotation binding
+ * @param attributeName
+ * the attribute name to look up
+ * @return
+ * @return the value of the attribute, or null if the attribute is not
+ * defined. The value can also be an Array of objects if the
+ * attribute is multi-valued.
+ * @throws CoreException
+ * the underlying CoreException thrown by the manipulated JDT
+ * APIs
+ */
+ public static Object resolveAnnotationAttributeValue(final IMember member, final CompilationUnit compilationUnit,
+ final Class<?> annotationClass, final String attributeName) throws CoreException {
+ IAnnotationBinding annotationBinding = JdtUtils.resolveAnnotationBinding(member, compilationUnit,
+ annotationClass);
+ if (annotationBinding != null) {
+ for (IMemberValuePairBinding binding : annotationBinding.getAllMemberValuePairs()) {
+ if (binding.getName().equals(attributeName)) {
+ return binding.getValue();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
* Resolves the fully qualified name of the annotation given its binding.
*
* @param annotationBinding
@@ -491,4 +523,32 @@
return problems;
}
+ /**
+ * Resolves the method parameters.
+ *
+ * @param javaMethod
+ * @param compilationUnit
+ * @param annotationType
+ * @return the method parameters
+ * @throws JavaModelException
+ */
+ public static List<ResourceMethodAnnotatedParameter> resolveMethodParameters(IMethod javaMethod,
+ CompilationUnit compilationUnit, Class<?> annotationType) throws JavaModelException {
+ List<ResourceMethodAnnotatedParameter> parameters = new ArrayList<ResourceMethodAnnotatedParameter>();
+ Map<IAnnotationBinding, ITypedRegion> bindings = JdtUtils.resolveMethodParamBindings(javaMethod,
+ compilationUnit, annotationType);
+ for (Entry<IAnnotationBinding, ITypedRegion> entry : bindings.entrySet()) {
+ IAnnotationBinding binding = entry.getKey();
+ ITypedRegion region = entry.getValue();
+ IMemberValuePairBinding[] allMemberValuePairs = binding.getAllMemberValuePairs();
+ IMemberValuePairBinding memberValuePair = allMemberValuePairs[0];
+ String annotationValue = (String) memberValuePair.getValue();
+ int lineNumber = compilationUnit.getLineNumber(region.getOffset());
+ parameters.add(new ResourceMethodAnnotatedParameter(region.getType(), annotationType.getName(),
+ annotationValue, region.getOffset(), region.getOffset() + region.getLength(), lineNumber));
+ }
+ Collections.sort(parameters);
+ return parameters;
+ }
+
}
Copied: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java (from rev 31413, trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/metamodel/ResourceMethodAnnotatedParameter.java)
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/utils/ResourceMethodAnnotatedParameter.java 2011-05-22 16:04:56 UTC (rev 31416)
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.core.utils;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.ws.jaxrs.core.metamodel.Validable;
+
+public class ResourceMethodAnnotatedParameter implements Validable, Comparable<ResourceMethodAnnotatedParameter> {
+
+ private final String parameterType;
+
+ private final String annotationType;
+
+ private final String annotationValue;
+
+ private final int charStart;
+
+ private final int charEnd;
+
+ private final int lineNumber;
+
+
+ /**
+ * Full constructor
+ * @param parent
+ * @param parameterName
+ * @param parameterType
+ * @param annotationType
+ * @param annotationValue
+ * @param charStart
+ * @param charEnd
+ * @param lineNumber
+ */
+ public ResourceMethodAnnotatedParameter(String parameterType,
+ String annotationType, String annotationValue, int charStart, int charEnd, int lineNumber) {
+ super();
+ this.parameterType = parameterType;
+ this.annotationType = annotationType;
+ this.annotationValue = annotationValue;
+ this.charStart = charStart;
+ this.charEnd = charEnd;
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void validate(IProgressMonitor progressMonitor) throws CoreException {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * @return the parameterType
+ */
+ public String getParameterType() {
+ return parameterType;
+ }
+
+ /**
+ * @return the annotationType
+ */
+ public String getAnnotationType() {
+ return annotationType;
+ }
+
+ /**
+ * @return the annotationValue
+ */
+ public String getAnnotationValue() {
+ return annotationValue;
+ }
+
+ /**
+ * @return the charStart
+ */
+ public int getCharStart() {
+ return charStart;
+ }
+
+ /**
+ * @return the charEnd
+ */
+ public int getCharEnd() {
+ return charEnd;
+ }
+
+ /**
+ * @return the lineNumber
+ */
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ /**
+ * Compares method parameters by their textual location
+ * {@inheritDoc}
+ * @param otherParam
+ * @return
+ */
+ @Override
+ public int compareTo(ResourceMethodAnnotatedParameter otherParam) {
+ return getCharStart() - otherParam.getCharStart();
+ }
+
+}
13 years, 1 month
JBoss Tools SVN: r31415 - trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2011-05-22 12:04:20 -0400 (Sun, 22 May 2011)
New Revision: 31415
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java
Log:
Refactoring pieces of the metamodel classes and JdtUtils API + Fixing incomplete jaxrs-api jar
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2011-05-22 16:04:11 UTC (rev 31414)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2011-05-22 16:04:20 UTC (rev 31415)
@@ -54,7 +54,7 @@
public class PathParamAnnotationValueCompletionProposalComputer implements IJavaCompletionProposalComputer {
/** Icon for completion proposals. */
- private Image icon = JBossJaxrsUIPlugin.getDefault().createImage("url_mapping.gif");
+ private final Image icon = JBossJaxrsUIPlugin.getDefault().createImage("url_mapping.gif");
/**
* {@inheritDoc}
@@ -119,7 +119,7 @@
* @throws CoreException
* in case of underlying exception
* @throws BadLocationException
- * @throws org.eclipse.jface.text.BadLocationException
+ * @throws org.eclipse.jface.text.BadLocationException
*/
private List<ICompletionProposal> internalComputePathParamProposals(JavaContentAssistInvocationContext javaContext,
IAnnotationBinding pathParamAnnotationBinding, IMethod method, CompilationUnit compilationUnit)
@@ -137,21 +137,20 @@
return completionProposals;
}
- private List<ICompletionProposal> generateCompletionProposal(IMember member, CompilationUnit compilationUnit, ITypedRegion region,
- String matchValue) throws CoreException {
+ private List<ICompletionProposal> generateCompletionProposal(IMember member, CompilationUnit compilationUnit,
+ ITypedRegion region, String matchValue) throws CoreException {
List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>();
- IAnnotationBinding pathAnnotationBinding = JdtUtils.resolveAnnotationBinding(member, compilationUnit,
- Path.class);
- String pathAnnotationValue = (String) JdtUtils.resolveAnnotationAttributeValue(pathAnnotationBinding, "value");
+ String pathAnnotationValue = (String) JdtUtils.resolveAnnotationAttributeValue(member, compilationUnit,
+ Path.class, "value");
if (pathAnnotationValue != null && pathAnnotationValue.contains("{") && pathAnnotationValue.contains("}")) {
List<String> uriParams = extractParamsFromUriTemplateFragment(pathAnnotationValue);
- for(String uriParam : uriParams) {
+ for (String uriParam : uriParams) {
String replacementValue = "\"" + uriParam + "\"";
if (replacementValue.startsWith(matchValue)) {
String displayString = uriParam + " - JAX-RS Mapping";
StyledString displayStyledString = new StyledString(displayString);
- displayStyledString.setStyle(uriParam.length(),
- displayString.length() - uriParam.length(), StyledString.QUALIFIER_STYLER);
+ displayStyledString.setStyle(uriParam.length(), displayString.length() - uriParam.length(),
+ StyledString.QUALIFIER_STYLER);
completionProposals.add(new AnnotationCompletionProposal(replacementValue, displayStyledString,
region, icon, member, compilationUnit));
}
@@ -159,7 +158,7 @@
}
return completionProposals;
}
-
+
private static List<String> extractParamsFromUriTemplateFragment(String fragment) {
List<String> params = new ArrayList<String>();
int beginIndex = -1;
13 years, 1 month