Author: rareddy
Date: 2010-08-16 13:58:22 -0400 (Mon, 16 Aug 2010)
New Revision: 2465
Added:
trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java
Removed:
trunk/jboss-integration/src/test/java/org/teiid/templates/connector/
Modified:
trunk/client/src/main/java/org/teiid/adminapi/DataPolicy.java
trunk/client/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java
trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
Log:
TEIID-1208: Enum objects were not being handled by the AdminObjectBuilder. The support has
been now added.
Modified: trunk/client/src/main/java/org/teiid/adminapi/DataPolicy.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/DataPolicy.java 2010-08-16 17:57:20 UTC
(rev 2464)
+++ trunk/client/src/main/java/org/teiid/adminapi/DataPolicy.java 2010-08-16 17:58:22 UTC
(rev 2465)
@@ -63,24 +63,24 @@
* Is "CREATE" allowed?
* @return
*/
- Boolean isAllowCreate();
+ Boolean getAllowCreate();
/**
* Is "SELECT" allowed?
* @return
*/
- Boolean isAllowRead();
+ Boolean getAllowRead();
/**
* Is "INSERT/UPDATE" allowed?
* @return
*/
- Boolean isAllowUpdate();
+ Boolean getAllowUpdate();
/**
* Is "DELETE" allowed?
* @return
*/
- Boolean isAllowDelete();
+ Boolean getAllowDelete();
}
}
Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2010-08-16
17:57:20 UTC (rev 2464)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -173,7 +173,7 @@
@Override
@ManagementProperty(description="Allows Create")
- public Boolean isAllowCreate() {
+ public Boolean getAllowCreate() {
return allowCreate;
}
@@ -183,7 +183,7 @@
@Override
@ManagementProperty(description="Allows Read")
- public Boolean isAllowRead() {
+ public Boolean getAllowRead() {
return allowRead;
}
@@ -193,7 +193,7 @@
@Override
@ManagementProperty(description="Allows Update")
- public Boolean isAllowUpdate() {
+ public Boolean getAllowUpdate() {
return allowUpdate;
}
@@ -203,7 +203,7 @@
@Override
@ManagementProperty(description="Allows Delete")
- public Boolean isAllowDelete() {
+ public Boolean getAllowDelete() {
return allowDelete;
}
@@ -213,16 +213,16 @@
public String getType() {
StringBuilder sb = new StringBuilder();
- if (Boolean.TRUE.equals(isAllowCreate())) {
+ if (Boolean.TRUE.equals(getAllowCreate())) {
sb.append("C");//$NON-NLS-1$
}
- if (Boolean.TRUE.equals(isAllowRead())) {
+ if (Boolean.TRUE.equals(getAllowRead())) {
sb.append("R");//$NON-NLS-1$
}
- if (Boolean.TRUE.equals(isAllowUpdate())) {
+ if (Boolean.TRUE.equals(getAllowUpdate())) {
sb.append("U");//$NON-NLS-1$
}
- if (Boolean.TRUE.equals(isAllowDelete())) {
+ if (Boolean.TRUE.equals(getAllowDelete())) {
sb.append("D");//$NON-NLS-1$
}
return sb.toString();
@@ -231,13 +231,13 @@
public Boolean allows(PermissionType type) {
switch (type) {
case CREATE:
- return isAllowCreate();
+ return getAllowCreate();
case READ:
- return isAllowRead();
+ return getAllowRead();
case UPDATE:
- return isAllowUpdate();
+ return getAllowUpdate();
case DELETE:
- return isAllowDelete();
+ return getAllowDelete();
}
throw new AssertionError();
}
Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2010-08-16
17:57:20 UTC (rev 2464)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -210,6 +210,10 @@
return getValidationErrors(Severity.ERROR);
}
+ public void setErrors(List<ValidationError> errors){
+ this.errors = errors;
+ }
+
public List<ValidationError> getValidationErrors(ValidationError.Severity
severity){
if (this.errors == null) {
return Collections.emptyList();
Modified: trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
--- trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-08-16
17:57:20 UTC (rev 2464)
+++ trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -174,12 +174,12 @@
for (DataPolicy.DataPermission p: permissions) {
if (p.getResourceName().equalsIgnoreCase("myTable.T1")) { //$NON-NLS-1$
- assertTrue(p.isAllowRead());
- assertNull(p.isAllowDelete());
+ assertTrue(p.getAllowRead());
+ assertNull(p.getAllowDelete());
}
else {
- assertFalse(p.isAllowRead());
- assertTrue(p.isAllowDelete());
+ assertFalse(p.getAllowRead());
+ assertTrue(p.getAllowDelete());
}
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-08-16
17:57:20 UTC (rev 2464)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -208,7 +208,7 @@
for (ManagedComponent mc: vdbComponents) {
String name = ManagedUtil.getSimpleValue(mc, "name",
String.class);//$NON-NLS-1$
int version = ManagedUtil.getSimpleValue(mc, "version",
Integer.class);//$NON-NLS-1$
- if (name.equals(vdbName) && version == vdbVersion) {
+ if (name.equalsIgnoreCase(vdbName) && version == vdbVersion) {
return mc;
}
}
Modified:
trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java 2010-08-16
17:57:20 UTC (rev 2464)
+++
trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/AdminObjectBuilder.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -69,6 +69,12 @@
if (type.isSimple()) {
PropertiesUtils.setBeanProperty(t, mp.getMappedName(),
((SimpleValue)value).getValue());
}
+ else if (type.isPrimitive()) {
+ PropertiesUtils.setBeanProperty(t, mp.getMappedName(),
((SimpleValue)value).getValue());
+ }
+ else if (type.isEnum()) {
+ PropertiesUtils.setBeanProperty(t, mp.getMappedName(),
((org.jboss.metatype.api.values.EnumValue)value).getValue());
+ }
else if (type.isProperties()) {
}
@@ -104,9 +110,17 @@
else if (elementType.isComposite()) {
list.addAll((List)MetaValueFactory.getInstance().unwrap(value));
}
-
+ else {
+ throw new TeiidRuntimeException("unsupported type"); //$NON-NLS-1$
+ }
PropertiesUtils.setBeanProperty(t, mp.getMappedName(), list);
}
+ else if (type.isGeneric()) {
+ throw new TeiidRuntimeException("unsupported type"); //$NON-NLS-1$
+ }
+ else if (type.isTable()|| type.isArray()) {
+ throw new TeiidRuntimeException("unsupported type"); //$NON-NLS-1$
+ }
}
}
return clazz.cast(t);
Added:
trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java
===================================================================
---
trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java
(rev 0)
+++
trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.adminapi.jboss;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
+import org.junit.Test;
+import org.teiid.adminapi.DataPolicy;
+import org.teiid.adminapi.Model;
+import org.teiid.adminapi.Translator;
+import org.teiid.adminapi.impl.DataPolicyMetadata;
+import org.teiid.adminapi.impl.ModelMetaData;
+import org.teiid.adminapi.impl.TranslatorMetaData;
+import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
+import org.teiid.translator.ExecutionFactory;
+
+@SuppressWarnings("nls")
+public class TestAdminObjectBuilder {
+
+ @Test
+ public void testVDB() {
+
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("myVDB");
+ vdb.setDescription("vdb description");
+ vdb.setVersion(1);
+ vdb.addProperty("vdb-property", "vdb-value");
+
+ ModelMetaData modelOne = new ModelMetaData();
+ modelOne.setName("model-one");
+ modelOne.addSourceMapping("s1", "translator",
"java:mybinding");
+ modelOne.setModelType(Model.Type.PHYSICAL);
+ modelOne.addProperty("model-prop", "model-value");
+ modelOne.addProperty("model-prop", "model-value-override");
+ modelOne.setVisible(false);
+ modelOne.addError("ERROR", "There is an error in VDB");
+ modelOne.setDescription("model description");
+
+ vdb.addModel(modelOne);
+
+ ModelMetaData modelTwo = new ModelMetaData();
+ modelTwo.setName("model-two");
+ modelTwo.addSourceMapping("s1", "translator",
"java:binding-one");
+ modelTwo.addSourceMapping("s2", "translator",
"java:binding-two");
+ modelTwo.setModelType(Model.Type.VIRTUAL);
+ modelTwo.addProperty("model-prop", "model-value");
+
+ vdb.addModel(modelTwo);
+
+ TranslatorMetaData t1 = new TranslatorMetaData();
+ t1.setName("oracleOverride");
+ t1.setType("oracle");
+ t1.addProperty("my-property", "my-value");
+ List<Translator> list = new ArrayList<Translator>();
+ list.add(t1);
+ vdb.setOverrideTranslators(list);
+
+ DataPolicyMetadata roleOne = new DataPolicyMetadata();
+ roleOne.setName("roleOne");
+ roleOne.setDescription("roleOne described");
+
+ PermissionMetaData perm1 = new PermissionMetaData();
+ perm1.setResourceName("myTable.T1");
+ perm1.setAllowRead(true);
+ roleOne.addPermission(perm1);
+
+ PermissionMetaData perm2 = new PermissionMetaData();
+ perm2.setResourceName("myTable.T2");
+ perm2.setAllowRead(false);
+ perm2.setAllowDelete(true);
+ roleOne.addPermission(perm2);
+
+ roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2"));
+
+ vdb.addDataPolicy(roleOne);
+
+ // convert to managed object and build the VDB out of MO
+ ManagedObjectFactory mof = ManagedObjectFactoryBuilder.create();
+ ManagedObject mo = mof.initManagedObject(vdb, null, null);
+ vdb = AdminObjectBuilder.buildAO(mo, VDBMetaData.class);
+
+ assertEquals("myVDB", vdb.getName());
+ assertEquals("vdb description", vdb.getDescription());
+ assertEquals(1, vdb.getVersion());
+ assertEquals("vdb-value", vdb.getPropertyValue("vdb-property"));
+
+ assertNotNull(vdb.getModel("model-one"));
+ assertNotNull(vdb.getModel("model-two"));
+ assertNull(vdb.getModel("model-unknown"));
+
+ modelOne = vdb.getModel("model-one");
+ assertEquals("model-one", modelOne.getName());
+ assertEquals("s1", modelOne.getSourceNames().get(0));
+ assertEquals(Model.Type.PHYSICAL, modelOne.getModelType());
+ assertEquals("model-value-override",
modelOne.getPropertyValue("model-prop"));
+ assertFalse(modelOne.isVisible());
+ assertEquals("model description", modelOne.getDescription());
+
+ modelTwo = vdb.getModel("model-two");
+ assertEquals("model-two", modelTwo.getName());
+ assertTrue(modelTwo.getSourceNames().contains("s1"));
+ assertTrue(modelTwo.getSourceNames().contains("s2"));
+ assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType()); // this is not persisted in
the XML
+ assertEquals("model-value",
modelTwo.getPropertyValue("model-prop"));
+
+
+ assertTrue(vdb.getValidityErrors().contains("There is an error in VDB"));
+
+ List<Translator> translators = vdb.getOverrideTranslators();
+ assertTrue(translators.size() == 1);
+
+ Translator translator = translators.get(0);
+ assertEquals("oracleOverride", translator.getName());
+ assertEquals("oracle", translator.getType());
+ assertEquals("my-value",
translator.getPropertyValue("my-property"));
+
+ List<DataPolicy> roles = vdb.getDataPolicies();
+
+ assertTrue(roles.size() == 1);
+
+ DataPolicyMetadata role = vdb.getDataPolicy("roleOne");
+ assertEquals("roleOne described", role.getDescription());
+ assertNotNull(role.getMappedRoleNames());
+ assertTrue(role.getMappedRoleNames().contains("ROLE1"));
+ assertTrue(role.getMappedRoleNames().contains("ROLE2"));
+
+ List<DataPolicy.DataPermission> permissions = role.getPermissions();
+ assertEquals(2, permissions.size());
+
+ for (DataPolicy.DataPermission p: permissions) {
+ if (p.getResourceName().equalsIgnoreCase("myTable.T1")) {
+ assertTrue(p.getAllowRead());
+ assertNull(p.getAllowDelete());
+ }
+ else {
+ assertFalse(p.getAllowRead());
+ assertTrue(p.getAllowDelete());
+ }
+ }
+ }
+
+ @Test
+ public void testTranslator() {
+ TranslatorMetaData tm = new TranslatorMetaData();
+
+ tm.setExecutionFactoryClass(ExecutionFactory.class);
+ tm.setName("Oracle");
+ tm.addProperty("ExtensionTranslationClassName",
"org.teiid.translator.jdbc.oracle.OracleSQLTranslator");
+
+ // convert to managed object and build the VDB out of MO
+ ManagedObjectFactory mof = ManagedObjectFactoryBuilder.create();
+ ManagedObject mo = mof.initManagedObject(tm, null, null);
+ tm = AdminObjectBuilder.buildAO(mo, TranslatorMetaData.class);
+
+ assertEquals("Oracle", tm.getName());
+ assertEquals(ExecutionFactory.class.getName(),
tm.getPropertyValue(Translator.EXECUTION_FACTORY_CLASS));
+ assertEquals("org.teiid.translator.jdbc.oracle.OracleSQLTranslator",
tm.getPropertyValue("ExtensionTranslationClassName"));
+ }
+}
Property changes on:
trunk/jboss-integration/src/test/java/org/teiid/adminapi/jboss/TestAdminObjectBuilder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java
===================================================================
---
trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java 2010-08-16
17:57:20 UTC (rev 2464)
+++
trunk/test-integration/db/src/test/java/org/teiid/adminapi/jboss/TestConnectorBindings.java 2010-08-16
17:58:22 UTC (rev 2465)
@@ -124,16 +124,16 @@
for(DataPolicy.DataPermission permission: permissions) {
if (permission.getResourceName().equals("myTable.T1")) {
- assertTrue(permission.isAllowRead());
- assertFalse(permission.isAllowCreate());
- assertFalse(permission.isAllowDelete());
- assertFalse(permission.isAllowUpdate());
+ assertTrue(permission.getAllowRead());
+ assertFalse(permission.getAllowCreate());
+ assertFalse(permission.getAllowDelete());
+ assertFalse(permission.getAllowUpdate());
}
else if (permission.getResourceName().equals("myTable.T2")) {
- assertFalse(permission.isAllowRead());
- assertFalse(permission.isAllowCreate());
- assertTrue(permission.isAllowDelete());
- assertFalse(permission.isAllowUpdate());
+ assertFalse(permission.getAllowRead());
+ assertFalse(permission.getAllowCreate());
+ assertTrue(permission.getAllowDelete());
+ assertFalse(permission.getAllowUpdate());
}
else {
fail("there are only two types of permissions");