Search in sources :

Example 1 with BaseModel

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);
}
Also used : Locale(java.util.Locale) JsonArray(javax.json.JsonArray) BaseModel(org.glassfish.admin.rest.model.BaseModel) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject) Test(org.testng.annotations.Test)

Example 2 with BaseModel

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"));
}
Also used : Locale(java.util.Locale) BaseModel(org.glassfish.admin.rest.model.BaseModel) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonParser(javax.json.stream.JsonParser) Test(org.testng.annotations.Test)

Example 3 with BaseModel

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());
}
Also used : BaseModel(org.glassfish.admin.rest.model.BaseModel) Method(java.lang.reflect.Method) ReferenceConstraint(com.sun.enterprise.config.serverbeans.customvalidators.ReferenceConstraint) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test)

Example 4 with BaseModel

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()));
}
Also used : BaseModel(org.glassfish.admin.rest.model.BaseModel) ModelExt2(org.glassfish.admin.rest.model.ModelExt2) ModelExt1(org.glassfish.admin.rest.model.ModelExt1) Test(org.testng.annotations.Test)

Example 5 with BaseModel

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);
}
Also used : RelatedModel(org.glassfish.admin.rest.model.RelatedModel) BaseModel(org.glassfish.admin.rest.model.BaseModel) Test(org.testng.annotations.Test)

Aggregations

BaseModel (org.glassfish.admin.rest.model.BaseModel)8 Test (org.testng.annotations.Test)8 Locale (java.util.Locale)4 JsonObject (javax.json.JsonObject)3 StringReader (java.io.StringReader)2 JsonParser (javax.json.stream.JsonParser)2 ReferenceConstraint (com.sun.enterprise.config.serverbeans.customvalidators.ReferenceConstraint)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 JsonArray (javax.json.JsonArray)1 ConstraintViolation (javax.validation.ConstraintViolation)1 ModelExt1 (org.glassfish.admin.rest.model.ModelExt1)1 ModelExt2 (org.glassfish.admin.rest.model.ModelExt2)1 RelatedModel (org.glassfish.admin.rest.model.RelatedModel)1