use of org.glassfish.admin.rest.model.BaseModel in project Payara by payara.
the class JsonUtilTest method testArrayEncoding.
@Test
public void testArrayEncoding() throws JsonException {
Locale locale = null;
BaseModel model = CompositeUtil.instance().getModel(BaseModel.class);
model.setStringArray(new String[] { "one", "two" });
JsonObject json = (JsonObject) JsonUtil.getJsonValue(model);
Assert.assertNotNull(json);
Object o = json.get("stringArray");
Assert.assertTrue(o instanceof JsonArray);
JsonArray array = (JsonArray) o;
Assert.assertEquals(array.size(), 2);
Assert.assertTrue(contains(array, "one"));
Assert.assertTrue(contains(array, "two"));
BaseModel model2 = CompositeUtil.instance().unmarshallClass(locale, BaseModel.class, json);
Assert.assertNotNull(model2);
Assert.assertNotNull(model2.getStringArray());
Assert.assertEquals(2, model2.getStringArray().length);
}
use of org.glassfish.admin.rest.model.BaseModel in project Payara by payara.
the class CompositeUtilTest method testDirtyFieldDetection.
@Test
public void testDirtyFieldDetection() throws JsonException {
Locale locale = null;
JsonParser parser = Json.createParser(new StringReader(JSON));
parser.next();
JsonObject o = parser.getObject();
BaseModel model = CompositeUtil.instance().unmarshallClass(locale, BaseModel.class, o);
RestModel rmi = (RestModel) model;
Assert.assertTrue(rmi.isSet("name"));
Assert.assertTrue(rmi.isSet("count"));
Assert.assertTrue(rmi.isSet("related"));
Assert.assertFalse(rmi.isSet("size"));
}
use of org.glassfish.admin.rest.model.BaseModel in project Payara by payara.
the class CompositeUtilTest method testAttributeReferenceProcessing.
@Test
public void testAttributeReferenceProcessing() throws Exception {
final CompositeUtil cu = CompositeUtil.instance();
BaseModel model = cu.getModel(BaseModel.class);
final Method clusterMethod = Cluster.class.getMethod("getConfigRef");
final Method modelMethod = model.getClass().getDeclaredMethod("getConfigRef");
Annotation[] fromCluster = clusterMethod.getAnnotations();
Annotation[] fromRestModel = modelMethod.getAnnotations();
Assert.assertEquals(fromCluster.length, fromRestModel.length);
Assert.assertEquals(clusterMethod.getAnnotation(ReferenceConstraint.RemoteKey.class).message(), modelMethod.getAnnotation(ReferenceConstraint.RemoteKey.class).message());
}
use of org.glassfish.admin.rest.model.BaseModel in project Payara by payara.
the class ModelExtensionTest method testModelExtension.
@Test
public void testModelExtension() {
BaseModel model = CompositeUtil.instance().getModel(BaseModel.class);
Assert.assertTrue(ModelExt1.class.isAssignableFrom(model.getClass()));
Assert.assertTrue(ModelExt2.class.isAssignableFrom(model.getClass()));
}
use of org.glassfish.admin.rest.model.BaseModel in project Payara by payara.
the class ModelExtensionTest method testNestedModels.
@Test
public void testNestedModels() {
BaseModel model = CompositeUtil.instance().getModel(BaseModel.class);
List<RelatedModel> related = model.getRelated();
Assert.assertNull(related);
RelatedModel rm = CompositeUtil.instance().getModel(RelatedModel.class);
rm.setId("1");
rm.setDescription("test");
related = new ArrayList<RelatedModel>();
related.add(rm);
model.setRelated(related);
related = model.getRelated();
Assert.assertEquals(related.size(), 1);
}
Aggregations