diff --git a/Jenkinsfile b/Jenkinsfile index 312c9840..517ec574 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,17 +1,7 @@ -@Library('sd')_ -def kubeLabel = getKubeLabel() - pipeline { - agent { - kubernetes { - label "${kubeLabel}" - cloud 'Kube mwdevel' - defaultContainer 'jnlp' - inheritFrom 'ci-template' - } - } - + agent { label 'java11' } + options { buildDiscarder(logRotator(numToKeepStr: '5')) timeout(time: 1, unit: 'HOURS') @@ -23,17 +13,13 @@ pipeline { stage('build') { steps { - container('runner') { - sh 'mvn -B clean compile' - } + sh 'mvn -B clean compile' } } stage('test') { steps { - container('runner') { - sh 'mvn -B clean test' - } + sh 'mvn -B clean test' script { currentBuild.result = 'SUCCESS' } @@ -41,18 +27,14 @@ pipeline { post { always { - container('runner') { - junit '**/target/surefire-reports/TEST-*.xml' - } + junit '**/target/surefire-reports/TEST-*.xml' } } } stage('package') { steps { - container('runner') { - sh 'mvn -B -DskipTests=true clean package' - } + sh 'mvn -B -DskipTests=true clean package' } } } diff --git a/src/main/java/it/grid/storm/namespace/model/SAInfo.java b/src/main/java/it/grid/storm/namespace/model/SAInfo.java index d5da79b4..b3812e50 100644 --- a/src/main/java/it/grid/storm/namespace/model/SAInfo.java +++ b/src/main/java/it/grid/storm/namespace/model/SAInfo.java @@ -7,200 +7,233 @@ import java.util.Iterator; import java.util.List; -public class SAInfo { - - private String name; - private String token; - private String voname; - private String root; - private String storageclass; - private List stfnRoot; - private String retentionPolicy; - private String accessLatency; - private List protocols; - private HttpPerms anonymous; - private long availableNearlineSpace; - private List approachableRules; - - // Must have no-argument constructor - public SAInfo() { - - } - - public String getName() { +import com.google.common.collect.Lists; - return name; - } - - public void setName(String name) { - - this.name = name; - } - - public String getToken() { - - return token; - } +public class SAInfo { - public void setToken(String token) { + private String name; + private String token; + private List vos; + private String root; + private String storageclass; + private List stfnRoot; + private String retentionPolicy; + private String accessLatency; + private List protocols; + private HttpPerms anonymous; + private long availableNearlineSpace; + private List approachableRules; - this.token = token; - } + // Must have no-argument constructor + public SAInfo() { - public String getVoname() { + } - return voname; - } + public String getName() { - public void setVoname(String voname) { + return name; + } - this.voname = voname; - } + public void setName(String name) { - public String getRoot() { + this.name = name; + } - return root; - } + public String getToken() { - public void setRoot(String root) { + return token; + } - this.root = root; - } + public void setToken(String token) { - public String getStorageclass() { + this.token = token; + } - return storageclass; - } + public List getVos() { - public void setStorageclass(String storageclass) { + return vos; + } - this.storageclass = storageclass; - } + public void setVos(List vos) { + this.vos = vos; + } - public List getStfnRoot() { + public String getRoot() { - return stfnRoot; - } + return root; + } - public void setStfnRoot(List stfnRoot) { + public void setRoot(String root) { - this.stfnRoot = stfnRoot; - } + this.root = root; + } - public String getRetentionPolicy() { + public String getStorageclass() { - return retentionPolicy; - } + return storageclass; + } - public void setRetentionPolicy(String retentionPolicy) { + public void setStorageclass(String storageclass) { - this.retentionPolicy = retentionPolicy; - } + this.storageclass = storageclass; + } - public String getAccessLatency() { + public List getStfnRoot() { - return accessLatency; - } + return stfnRoot; + } - public void setAccessLatency(String accessLatency) { + public void setStfnRoot(List stfnRoot) { - this.accessLatency = accessLatency; - } + this.stfnRoot = stfnRoot; + } - public List getProtocols() { + public String getRetentionPolicy() { - return protocols; - } + return retentionPolicy; + } - public void setProtocols(List protocols) { + public void setRetentionPolicy(String retentionPolicy) { - this.protocols = protocols; - } + this.retentionPolicy = retentionPolicy; + } - public HttpPerms getAnonymous() { + public String getAccessLatency() { - return anonymous; - } + return accessLatency; + } - public void setAnonymous(HttpPerms anonymous) { + public void setAccessLatency(String accessLatency) { - this.anonymous = anonymous; - } + this.accessLatency = accessLatency; + } - public long getAvailableNearlineSpace() { + public List getProtocols() { - return availableNearlineSpace; - } + return protocols; + } - public void setAvailableNearlineSpace(long availableNearlineSpace) { + public void setProtocols(List protocols) { - this.availableNearlineSpace = availableNearlineSpace; - } + this.protocols = protocols; + } - public List getApproachableRules() { + public HttpPerms getAnonymous() { - return approachableRules; - } + return anonymous; + } - public void setApproachableRules(List approachableRules) { + public void setAnonymous(HttpPerms anonymous) { - this.approachableRules = approachableRules; - } + this.anonymous = anonymous; + } - public static SAInfo buildFromVFS(VirtualFS vfs) throws NamespaceException { + public long getAvailableNearlineSpace() { - SAInfo sa = new SAInfo(); + return availableNearlineSpace; + } - sa.setName(vfs.getAliasName()); - sa.setToken(vfs.getSpaceTokenDescription()); - sa.setVoname(vfs.getApproachableRules().get(0).getSubjectRules() - .getVONameMatchingRule().getVOName()); - sa.setRoot(vfs.getRootPath()); - sa.setStfnRoot(new ArrayList()); - for (MappingRule rule : vfs.getMappingRules()) { - sa.getStfnRoot().add(rule.getStFNRoot()); - } - sa.setProtocols(new ArrayList()); - Iterator protocolsIterator = vfs.getCapabilities() - .getAllManagedProtocols().iterator(); - while (protocolsIterator.hasNext()) { - sa.getProtocols().add(protocolsIterator.next().getSchema()); - } - if (vfs.isHttpWorldReadable()) { - if (vfs.isApproachableByAnonymous()) { - sa.setAnonymous(HttpPerms.READWRITE); - } else { - sa.setAnonymous(HttpPerms.READ); - } - } else { - sa.setAnonymous(HttpPerms.NOREAD); - } - sa.setStorageclass(vfs.getStorageClassType().getStorageClassTypeString()); - sa.setRetentionPolicy(vfs.getProperties().getRetentionPolicy() - .getRetentionPolicyName()); - sa.setAccessLatency(vfs.getProperties().getAccessLatency() - .getAccessLatencyName()); - sa.setAvailableNearlineSpace(vfs.getAvailableNearlineSpace().value()); - sa.setApproachableRules(new ArrayList()); - for (ApproachableRule rule : vfs.getApproachableRules()) { - if (rule.getSubjectRules().getDNMatchingRule().isMatchAll() - && rule.getSubjectRules().getVONameMatchingRule().isMatchAll()) { - continue; - } - if (!rule.getSubjectRules().getDNMatchingRule().isMatchAll()) { - sa.getApproachableRules().add( - rule.getSubjectRules().getDNMatchingRule() - .toShortSlashSeparatedString()); - } - if (!rule.getSubjectRules().getVONameMatchingRule().isMatchAll()) { - sa.getApproachableRules().add( - "vo:" + rule.getSubjectRules().getVONameMatchingRule().getVOName()); - } - } - if (sa.getApproachableRules().size() == 0) { - sa.getApproachableRules().add("'ALL'"); - } - - return sa; - } -} \ No newline at end of file + public void setAvailableNearlineSpace(long availableNearlineSpace) { + + this.availableNearlineSpace = availableNearlineSpace; + } + + public List getApproachableRules() { + + return approachableRules; + } + + public void setApproachableRules(List approachableRules) { + + this.approachableRules = approachableRules; + } + + public static SAInfo buildFromVFS(VirtualFS vfs) throws NamespaceException { + + SAInfo sa = new SAInfo(); + + sa.setName(vfs.getAliasName()); + sa.setToken(vfs.getSpaceTokenDescription()); + List vos = Lists.newArrayList(); + vfs.getApproachableRules().forEach(ar -> { + vos.add(ar.getSubjectRules().getVONameMatchingRule().getVOName()); + }); + sa.setVos(vos); + sa.setRoot(vfs.getRootPath()); + sa.setStfnRoot(new ArrayList()); + for (MappingRule rule : vfs.getMappingRules()) { + sa.getStfnRoot().add(rule.getStFNRoot()); + } + sa.setProtocols(new ArrayList()); + Iterator protocolsIterator = + vfs.getCapabilities().getAllManagedProtocols().iterator(); + while (protocolsIterator.hasNext()) { + sa.getProtocols().add(protocolsIterator.next().getSchema()); + } + if (vfs.isHttpWorldReadable()) { + if (vfs.isApproachableByAnonymous()) { + sa.setAnonymous(HttpPerms.READWRITE); + } else { + sa.setAnonymous(HttpPerms.READ); + } + } else { + sa.setAnonymous(HttpPerms.NOREAD); + } + sa.setStorageclass(vfs.getStorageClassType().getStorageClassTypeString()); + sa.setRetentionPolicy(vfs.getProperties().getRetentionPolicy().getRetentionPolicyName()); + sa.setAccessLatency(vfs.getProperties().getAccessLatency().getAccessLatencyName()); + sa.setAvailableNearlineSpace(vfs.getAvailableNearlineSpace().value()); + sa.setApproachableRules(new ArrayList()); + for (ApproachableRule rule : vfs.getApproachableRules()) { + if (rule.getSubjectRules().getDNMatchingRule().isMatchAll() + && rule.getSubjectRules().getVONameMatchingRule().isMatchAll()) { + continue; + } + if (!rule.getSubjectRules().getDNMatchingRule().isMatchAll()) { + sa.getApproachableRules() + .add(rule.getSubjectRules().getDNMatchingRule().toShortSlashSeparatedString()); + } + if (!rule.getSubjectRules().getVONameMatchingRule().isMatchAll()) { + sa.getApproachableRules() + .add("vo:" + rule.getSubjectRules().getVONameMatchingRule().getVOName()); + } + } + if (sa.getApproachableRules().size() == 0) { + sa.getApproachableRules().add("'ALL'"); + } + + return sa; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SAInfo [name="); + builder.append(name); + builder.append(", token="); + builder.append(token); + builder.append(", vos="); + builder.append(vos); + builder.append(", root="); + builder.append(root); + builder.append(", storageclass="); + builder.append(storageclass); + builder.append(", stfnRoot="); + builder.append(stfnRoot); + builder.append(", retentionPolicy="); + builder.append(retentionPolicy); + builder.append(", accessLatency="); + builder.append(accessLatency); + builder.append(", protocols="); + builder.append(protocols); + builder.append(", anonymous="); + builder.append(anonymous); + builder.append(", availableNearlineSpace="); + builder.append(availableNearlineSpace); + builder.append(", approachableRules="); + builder.append(approachableRules); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/it/grid/storm/namespace/model/SAInfoV13.java b/src/main/java/it/grid/storm/namespace/model/SAInfoV13.java new file mode 100644 index 00000000..8f819d7c --- /dev/null +++ b/src/main/java/it/grid/storm/namespace/model/SAInfoV13.java @@ -0,0 +1,206 @@ +package it.grid.storm.namespace.model; + +import it.grid.storm.namespace.NamespaceException; +import it.grid.storm.namespace.remote.Constants.HttpPerms; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class SAInfoV13 { + + private String name; + private String token; + private String voname; + private String root; + private String storageclass; + private List stfnRoot; + private String retentionPolicy; + private String accessLatency; + private List protocols; + private HttpPerms anonymous; + private long availableNearlineSpace; + private List approachableRules; + + // Must have no-argument constructor + public SAInfoV13() { + + } + + public String getName() { + + return name; + } + + public void setName(String name) { + + this.name = name; + } + + public String getToken() { + + return token; + } + + public void setToken(String token) { + + this.token = token; + } + + public String getVoname() { + + return voname; + } + + public void setVoname(String voname) { + + this.voname = voname; + } + + public String getRoot() { + + return root; + } + + public void setRoot(String root) { + + this.root = root; + } + + public String getStorageclass() { + + return storageclass; + } + + public void setStorageclass(String storageclass) { + + this.storageclass = storageclass; + } + + public List getStfnRoot() { + + return stfnRoot; + } + + public void setStfnRoot(List stfnRoot) { + + this.stfnRoot = stfnRoot; + } + + public String getRetentionPolicy() { + + return retentionPolicy; + } + + public void setRetentionPolicy(String retentionPolicy) { + + this.retentionPolicy = retentionPolicy; + } + + public String getAccessLatency() { + + return accessLatency; + } + + public void setAccessLatency(String accessLatency) { + + this.accessLatency = accessLatency; + } + + public List getProtocols() { + + return protocols; + } + + public void setProtocols(List protocols) { + + this.protocols = protocols; + } + + public HttpPerms getAnonymous() { + + return anonymous; + } + + public void setAnonymous(HttpPerms anonymous) { + + this.anonymous = anonymous; + } + + public long getAvailableNearlineSpace() { + + return availableNearlineSpace; + } + + public void setAvailableNearlineSpace(long availableNearlineSpace) { + + this.availableNearlineSpace = availableNearlineSpace; + } + + public List getApproachableRules() { + + return approachableRules; + } + + public void setApproachableRules(List approachableRules) { + + this.approachableRules = approachableRules; + } + + public static SAInfoV13 buildFromVFS(VirtualFS vfs) throws NamespaceException { + + SAInfoV13 sa = new SAInfoV13(); + + sa.setName(vfs.getAliasName()); + sa.setToken(vfs.getSpaceTokenDescription()); + sa.setVoname(vfs.getApproachableRules().get(0).getSubjectRules() + .getVONameMatchingRule().getVOName()); + sa.setRoot(vfs.getRootPath()); + sa.setStfnRoot(new ArrayList()); + for (MappingRule rule : vfs.getMappingRules()) { + sa.getStfnRoot().add(rule.getStFNRoot()); + } + sa.setProtocols(new ArrayList()); + Iterator protocolsIterator = vfs.getCapabilities() + .getAllManagedProtocols().iterator(); + while (protocolsIterator.hasNext()) { + sa.getProtocols().add(protocolsIterator.next().getSchema()); + } + if (vfs.isHttpWorldReadable()) { + if (vfs.isApproachableByAnonymous()) { + sa.setAnonymous(HttpPerms.READWRITE); + } else { + sa.setAnonymous(HttpPerms.READ); + } + } else { + sa.setAnonymous(HttpPerms.NOREAD); + } + sa.setStorageclass(vfs.getStorageClassType().getStorageClassTypeString()); + sa.setRetentionPolicy(vfs.getProperties().getRetentionPolicy() + .getRetentionPolicyName()); + sa.setAccessLatency(vfs.getProperties().getAccessLatency() + .getAccessLatencyName()); + sa.setAvailableNearlineSpace(vfs.getAvailableNearlineSpace().value()); + sa.setApproachableRules(new ArrayList()); + for (ApproachableRule rule : vfs.getApproachableRules()) { + if (rule.getSubjectRules().getDNMatchingRule().isMatchAll() + && rule.getSubjectRules().getVONameMatchingRule().isMatchAll()) { + continue; + } + if (!rule.getSubjectRules().getDNMatchingRule().isMatchAll()) { + sa.getApproachableRules().add( + rule.getSubjectRules().getDNMatchingRule() + .toShortSlashSeparatedString()); + } + if (!rule.getSubjectRules().getVONameMatchingRule().isMatchAll()) { + sa.getApproachableRules().add( + "vo:" + rule.getSubjectRules().getVONameMatchingRule().getVOName()); + } + } + if (sa.getApproachableRules().size() == 0) { + sa.getApproachableRules().add("'ALL'"); + } + + return sa; + } +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/namespace/remote/Constants.java b/src/main/java/it/grid/storm/namespace/remote/Constants.java index 2651ddb1..6d326d78 100644 --- a/src/main/java/it/grid/storm/namespace/remote/Constants.java +++ b/src/main/java/it/grid/storm/namespace/remote/Constants.java @@ -20,7 +20,8 @@ public class Constants { public static final String VERSION_1_0 = "1.0"; public static final String VERSION_1_1 = "1.1"; public static final String VERSION_1_2 = "1.2"; - public static final String VERSION = "1.3"; + public static final String VERSION_1_3 = "1.3"; + public static final String VERSION = "1.4"; public static final String LIST_ALL_KEY = "StorageAreaList"; public static final char VFS_LIST_SEPARATOR = ':'; public static final String VFS_NAME_KEY = "name"; diff --git a/src/main/java/it/grid/storm/namespace/remote/resource/VirtualFSResourceCompat_1_3.java b/src/main/java/it/grid/storm/namespace/remote/resource/VirtualFSResourceCompat_1_3.java new file mode 100644 index 00000000..5595f9bf --- /dev/null +++ b/src/main/java/it/grid/storm/namespace/remote/resource/VirtualFSResourceCompat_1_3.java @@ -0,0 +1,53 @@ +package it.grid.storm.namespace.remote.resource; + +import java.util.List; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.Maps; + +import it.grid.storm.namespace.NamespaceDirector; +import it.grid.storm.namespace.NamespaceException; +import it.grid.storm.namespace.model.SAInfoV13; +import it.grid.storm.namespace.model.VirtualFS; +import it.grid.storm.namespace.remote.Constants; + +/** + * @author Michele Dibenedetto + */ +@Path("/" + Constants.RESOURCE + "/" + Constants.VERSION_1_3) +public class VirtualFSResourceCompat_1_3 { + + private static final Logger log = LoggerFactory.getLogger(VirtualFSResourceCompat_1_3.class); + + /** + * @return + */ + @GET + @Path("/" + Constants.LIST_ALL_VFS) + @Produces(MediaType.APPLICATION_JSON) + public Map listVFS() { + + log.debug("Serving VFS resource listing"); + List vfsCollection = NamespaceDirector.getNamespace().getAllDefinedVFS(); + Map output = Maps.newHashMap(); + + for (VirtualFS vfs : vfsCollection) { + try { + output.put(vfs.getAliasName(), SAInfoV13.buildFromVFS(vfs)); + } catch (NamespaceException e) { + log.error(e.getMessage()); + } + } + + return output; + } + +} diff --git a/src/main/java/it/grid/storm/rest/RestServer.java b/src/main/java/it/grid/storm/rest/RestServer.java index bc207fff..33f88cbf 100644 --- a/src/main/java/it/grid/storm/rest/RestServer.java +++ b/src/main/java/it/grid/storm/rest/RestServer.java @@ -47,6 +47,7 @@ import it.grid.storm.info.remote.resources.SpaceStatusResource; import it.grid.storm.metrics.NamedInstrumentedSelectChannelConnector; import it.grid.storm.metrics.NamedInstrumentedThreadPool; +import it.grid.storm.namespace.remote.resource.VirtualFSResourceCompat_1_3; import it.grid.storm.namespace.remote.resource.VirtualFSResource; import it.grid.storm.namespace.remote.resource.VirtualFSResourceCompat_1_0; import it.grid.storm.namespace.remote.resource.VirtualFSResourceCompat_1_1; @@ -121,6 +122,7 @@ private void configure() { resourceConfig.register(VirtualFSResourceCompat_1_0.class); resourceConfig.register(VirtualFSResourceCompat_1_1.class); resourceConfig.register(VirtualFSResourceCompat_1_2.class); + resourceConfig.register(VirtualFSResourceCompat_1_3.class); resourceConfig.register(StormEAResource.class); resourceConfig.register(Metadata.class); resourceConfig.register(Ping.class); diff --git a/src/test/java/it/grid/storm/namespace/model/SAInfoTest.java b/src/test/java/it/grid/storm/namespace/model/SAInfoV13Test.java similarity index 91% rename from src/test/java/it/grid/storm/namespace/model/SAInfoTest.java rename to src/test/java/it/grid/storm/namespace/model/SAInfoV13Test.java index c9393a95..051e7695 100644 --- a/src/test/java/it/grid/storm/namespace/model/SAInfoTest.java +++ b/src/test/java/it/grid/storm/namespace/model/SAInfoV13Test.java @@ -14,17 +14,17 @@ import it.grid.storm.namespace.remote.Constants.HttpPerms; -public class SAInfoTest { +public class SAInfoV13Test { - private static final Logger log = LoggerFactory.getLogger(SAInfoTest.class); + private static final Logger log = LoggerFactory.getLogger(SAInfoV13Test.class); private static final String JSON_STRING = "{\"name\":\"test.vo\",\"token\":\"TESTVO_TOKEN\",\"voname\":\"test.vo\",\"root\":\"/storage/test.vo\",\"storageclass\":\"T1D0\",\"stfnRoot\":[\"/test.vo\"],\"retentionPolicy\":\"CUSTODIAL\",\"accessLatency\":\"ONLINE\",\"protocols\":[\"xroot\",\"webdav\"],\"anonymous\":\"NOREAD\",\"availableNearlineSpace\":20000000,\"approachableRules\":[\"Fake-DN-Matching-Rule\"]}"; - private static final SAInfo saInfo; + private static final SAInfoV13 saInfo; static { - saInfo = new SAInfo(); + saInfo = new SAInfoV13(); saInfo.setName("test.vo"); saInfo.setToken("TESTVO_TOKEN"); saInfo.setVoname("test.vo"); @@ -50,7 +50,7 @@ public void testWrite() throws JsonProcessingException { @Test public void testRead() throws IOException { ObjectMapper mapper = new ObjectMapper(); - SAInfo saInfoRead = mapper.readValue(JSON_STRING.getBytes(), SAInfo.class); + SAInfoV13 saInfoRead = mapper.readValue(JSON_STRING.getBytes(), SAInfoV13.class); log.info("sa info read {}", saInfoRead); assertEquals(saInfoRead.getName(), saInfo.getName()); assertEquals(saInfoRead.getToken(), saInfo.getToken()); diff --git a/src/test/java/it/grid/storm/namespace/model/SAInfoV14Test.java b/src/test/java/it/grid/storm/namespace/model/SAInfoV14Test.java new file mode 100644 index 00000000..40eeb48b --- /dev/null +++ b/src/test/java/it/grid/storm/namespace/model/SAInfoV14Test.java @@ -0,0 +1,61 @@ +package it.grid.storm.namespace.model; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; + +import it.grid.storm.namespace.remote.Constants.HttpPerms; + +public class SAInfoV14Test { + + private static final Logger log = LoggerFactory.getLogger(SAInfoV14Test.class); + + private static final String JSON_STRING = + "{\"name\":\"test.vo\",\"token\":\"TESTVO_TOKEN\",\"vos\":[\"test.vo\",\"test.vo.2\"],\"root\":\"/storage/test.vo\",\"storageclass\":\"T1D0\",\"stfnRoot\":[\"/test.vo\"],\"retentionPolicy\":\"CUSTODIAL\",\"accessLatency\":\"ONLINE\",\"protocols\":[\"xroot\",\"webdav\"],\"anonymous\":\"NOREAD\",\"availableNearlineSpace\":20000000,\"approachableRules\":[\"Fake-DN-Matching-Rule\"]}"; + + private static final SAInfo saInfo; + + static { + saInfo = new SAInfo(); + saInfo.setName("test.vo"); + saInfo.setToken("TESTVO_TOKEN"); + saInfo.setVos(Lists.newArrayList("test.vo", "test.vo.2")); + saInfo.setRoot("/storage/test.vo"); + saInfo.setStorageclass("T1D0"); + saInfo.setStfnRoot(Lists.newArrayList("/test.vo")); + saInfo.setRetentionPolicy(RetentionPolicy.CUSTODIAL.getRetentionPolicyName()); + saInfo.setAccessLatency(AccessLatency.ONLINE.getAccessLatencyName()); + saInfo.setProtocols(Lists.newArrayList("xroot", "webdav")); + saInfo.setAnonymous(HttpPerms.NOREAD); + saInfo.setAvailableNearlineSpace(20000000); + saInfo.setApproachableRules(Lists.newArrayList("Fake-DN-Matching-Rule")); + } + + @Test + public void testWrite() throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(saInfo); + log.info("Object as JSON String: {}", jsonString); + assertEquals(jsonString.replaceAll(" ", ""), JSON_STRING.replaceAll(" ", "")); + } + + @Test + public void testRead() throws IOException { + ObjectMapper mapper = new ObjectMapper(); + SAInfo saInfoRead = mapper.readValue(JSON_STRING.getBytes(), SAInfo.class); + log.info("sa info read {}", saInfoRead); + assertEquals(saInfoRead.getName(), saInfo.getName()); + assertEquals(saInfoRead.getToken(), saInfo.getToken()); + } + + + +}