1 package org.kuali.common.devops.vagrant.cloud.model.test; 2 3 import static com.fasterxml.jackson.databind.PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES; 4 import static java.lang.String.format; 5 import static org.junit.Assert.assertEquals; 6 import static org.kuali.common.core.json.jackson.ObjectMappers.buildDefaultMapper; 7 import static org.kuali.common.devops.project.KualiDevOpsProjectConstants.KUALI_DEVOPS_PID; 8 import static org.kuali.common.util.log.Loggers.newLogger; 9 import static org.kuali.common.util.project.ProjectUtils.getClasspathPrefix; 10 11 import org.junit.Test; 12 import org.kuali.common.core.json.api.JsonService; 13 import org.kuali.common.core.json.jackson.JacksonJsonService; 14 import org.kuali.common.devops.vagrant.cloud.model.Version; 15 import org.kuali.common.util.LocationUtils; 16 import org.slf4j.Logger; 17 18 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.google.common.base.Splitter; 20 21 public class VersionTest { 22 23 private static final Logger logger = newLogger(); 24 25 @Test 26 public void test() { 27 ObjectMapper mapper = buildDefaultMapper(); 28 mapper.setPropertyNamingStrategy(CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); 29 JsonService json = new JacksonJsonService(mapper); 30 String location = getClasspathPrefix(KUALI_DEVOPS_PID) + "/virtualbox/version.json"; 31 String text = LocationUtils.toString(location); 32 Version version = json.readString(text, Version.class); 33 info(json, version); 34 String expected = json.writeString(version); 35 String actual = json.writeString(json.readString(text, Version.class)); 36 assertEquals(expected, actual); 37 } 38 39 protected static <T> void info(JsonService json, T reference) { 40 String text = json.writeString(reference); 41 Iterable<String> lines = Splitter.on('\n').split(text); 42 for (String line : lines) { 43 info("%s", line); 44 } 45 } 46 47 protected static void debug(String msg, Object... args) { 48 logger.debug((args == null || args.length == 0) ? msg : format(msg, args)); 49 } 50 51 protected static void info(String msg, Object... args) { 52 logger.info((args == null || args.length == 0) ? msg : format(msg, args)); 53 } 54 55 }