You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scout-dev@ws.apache.org by jb...@apache.org on 2004/12/26 01:41:07 UTC
svn commit: r123351 - in webservices/scout/trunk/modules/scout/src: java/org/apache/ws/scout/registry java/org/apache/ws/scout/registry/infomodel test/org/apache/ws/scout/registry/infomodel
Author: jboynes
Date: Sat Dec 25 16:41:05 2004
New Revision: 123351
URL: http://svn.apache.org/viewcvs?view=rev&rev=123351
Log:
add test case for SlotImpl; fix equals and spec contract for values
Added:
webservices/scout/trunk/modules/scout/src/test/org/apache/ws/scout/registry/infomodel/SlotTest.java
Modified:
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java
webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java
Modified: webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java
Url: http://svn.apache.org/viewcvs/webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java?view=diff&rev=123351&p1=webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java&r1=123350&p2=webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java&r2=123351
==============================================================================
--- webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java (original)
+++ webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/LifeCycleManagerImpl.java Sat Dec 25 16:41:05 2004
@@ -141,7 +141,7 @@
throw new UnsupportedCapabilityException();
} else if (LifeCycleManager.SLOT.equals(interfaceName))
{
- return new SlotImpl(this);
+ return new SlotImpl();
} else if (LifeCycleManager.SPECIFICATION_LINK.equals(interfaceName))
{
return new SpecificationLinkImpl(this);
Modified: webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java
Url: http://svn.apache.org/viewcvs/webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java?view=diff&rev=123351&p1=webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java&r1=123350&p2=webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java&r2=123351
==============================================================================
--- webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java (original)
+++ webservices/scout/trunk/modules/scout/src/java/org/apache/ws/scout/registry/infomodel/SlotImpl.java Sat Dec 25 16:41:05 2004
@@ -18,8 +18,9 @@
import javax.xml.registry.infomodel.Slot;
import javax.xml.registry.JAXRException;
- import javax.xml.registry.LifeCycleManager;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
/**
* Implements Jaxr API
@@ -32,12 +33,12 @@
private String slotType;
private String name;
private Collection values;
- private LifeCycleManager lcm;
- public SlotImpl(LifeCycleManager lifeCycleManager)
+ public SlotImpl()
{
- lcm = lifeCycleManager;
+ values = Collections.EMPTY_SET;
}
+
public String getName() throws JAXRException
{
return name;
@@ -65,7 +66,32 @@
public void setValues(Collection collection) throws JAXRException
{
- values = collection;
+ if (collection == null) {
+ throw new IllegalArgumentException("values cannot be null");
+ }
+ // "the value of a Slot is locally unique within a slot instance"
+ // to enforce this, convert the supplied Collection to a Set
+ values = new HashSet(collection);
+ }
+
+ /**
+ * Slots can be used in Collections but the spec does not define equals()
+ * We define two slots with the same name as being equal as the spec says
+ * name is unique within the scope of the RegistryObject.
+ */
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof SlotImpl)) return false;
+
+ final SlotImpl slot = (SlotImpl) o;
+
+ if (name != null ? !name.equals(slot.name) : slot.name != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return (name != null ? name.hashCode() : 0);
}
}
Added: webservices/scout/trunk/modules/scout/src/test/org/apache/ws/scout/registry/infomodel/SlotTest.java
Url: http://svn.apache.org/viewcvs/webservices/scout/trunk/modules/scout/src/test/org/apache/ws/scout/registry/infomodel/SlotTest.java?view=auto&rev=123351
==============================================================================
--- (empty file)
+++ webservices/scout/trunk/modules/scout/src/test/org/apache/ws/scout/registry/infomodel/SlotTest.java Sat Dec 25 16:41:05 2004
@@ -0,0 +1,90 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.scout.registry.infomodel;
+
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.HashSet;
+import javax.xml.registry.infomodel.Slot;
+import javax.xml.registry.JAXRException;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SlotTest extends TestCase {
+ private Slot slot;
+
+ public void testEmptySlot() throws JAXRException {
+ slot = new SlotImpl();
+ assertNull(slot.getName());
+ assertNull(slot.getSlotType());
+ assertNotNull(slot.getValues()); // values may be empty but not null
+ assertTrue(slot.getValues().isEmpty());
+ }
+
+ public void testName() throws JAXRException {
+ slot.setName("Test Name");
+ assertEquals("Test Name", slot.getName());
+ }
+
+ public void testType() throws JAXRException {
+ slot.setSlotType("Test Type");
+ assertEquals("Test Type", slot.getSlotType());
+ }
+
+ public void testValues() throws JAXRException {
+ // check duplicate values are removed
+ Collection values = new ArrayList();
+ values.add("Value 1");
+ values.add("Value 2");
+ values.add("Value 2");
+ slot.setValues(values);
+
+ values = new HashSet();
+ values.add("Value 1");
+ values.add("Value 2");
+ assertEquals(values, slot.getValues());
+ }
+
+ public void testNullValues() throws JAXRException {
+ try {
+ slot.setValues(null);
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // ok
+ }
+ }
+
+ public void testEquals() throws JAXRException {
+ Slot slot1 = new SlotImpl();
+ Slot slot2 = new SlotImpl();
+ assertTrue(slot1.equals(slot2));
+ slot1.setName("test");
+ assertFalse(slot1.equals(slot2));
+ slot2.setName("test");
+ assertTrue(slot1.equals(slot2));
+ slot1.setName(null);
+ assertFalse(slot1.equals(slot2));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ slot = new SlotImpl();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: scout-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: scout-dev-help@ws.apache.org