Lucio Lelii 2016-06-15 11:46:54 +00:00
parent fea33de67b
commit 68ceb8f9fd
3 changed files with 28 additions and 11 deletions

View File

@ -6,13 +6,16 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="auhtorization-endpoint")
@XmlRootElement(name="authorization-endpoint")
@XmlAccessorType(XmlAccessType.FIELD)
public final class AuthorizationEndpoint implements Comparable<AuthorizationEndpoint>{
@XmlAttribute
private int priority = 0;
@XmlElement
private String infrastructure;
@XmlElement
private String host;
@ -21,13 +24,18 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
protected AuthorizationEndpoint() {}
public AuthorizationEndpoint(int priority, String host, int port) {
public AuthorizationEndpoint(String infrastructure, int priority, String host, int port) {
super();
this.infrastructure = infrastructure;
this.host = host;
this.priority = priority;
this.port = port;
}
protected String getInfrastructure() {
return infrastructure;
}
public String getHost() {
return host;
}
@ -51,7 +59,7 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
@Override
public String toString() {
return "AuthorizationEndpoint [priority=" + priority + ", host=" + host
return "AuthorizationEndpoint [infrastructure= "+infrastructure+" priority=" + priority + ", host=" + host
+ ", port=" + port + "]";
}
@ -60,6 +68,8 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
final int prime = 31;
int result = 1;
result = prime * result + ((host == null) ? 0 : host.hashCode());
result = prime * result
+ ((infrastructure == null) ? 0 : infrastructure.hashCode());
result = prime * result + port;
result = prime * result + priority;
return result;
@ -79,11 +89,18 @@ public final class AuthorizationEndpoint implements Comparable<AuthorizationEndp
return false;
} else if (!host.equals(other.host))
return false;
if (infrastructure == null) {
if (other.infrastructure != null)
return false;
} else if (!infrastructure.equals(other.infrastructure))
return false;
if (port != other.port)
return false;
if (priority != other.priority)
return false;
return true;
}
}

View File

@ -1 +1 @@
<auhtorization-endpoint priority="10"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></auhtorization-endpoint>
<authorization-endpoint priority="10"><host>node7.d.d4science.research-infrastructures.eu</host><port>9000</port></authorization-endpoint>

View File

@ -25,7 +25,7 @@ public class EndpointBinder {
public void bind() throws Exception{
JAXBContext context = getContext();
StringWriter sw = new StringWriter();
AuthorizationEndpoint ae1 = new AuthorizationEndpoint(2, "146.48.85.179", 8080);
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra", 2, "146.48.85.179", 8080);
context.createMarshaller().marshal(ae1, sw);
AuthorizationEndpoint ae2 = (AuthorizationEndpoint)context.createUnmarshaller().unmarshal(new StringReader(sw.toString()));
Assert.assertEquals(ae1, ae2);
@ -33,17 +33,17 @@ public class EndpointBinder {
@Test
public void compare(){
AuthorizationEndpoint ae1 = new AuthorizationEndpoint(2, "146.48.85.179", 8080);
AuthorizationEndpoint ae2 = new AuthorizationEndpoint(1, "146.48.85.179", 8080);
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra", 2, "146.48.85.179", 8080);
AuthorizationEndpoint ae2 = new AuthorizationEndpoint("/myInfra", 1, "146.48.85.179", 8080);
Assert.assertTrue(ae1.compareTo(ae2)>0);
}
@Test
public void order(){
AuthorizationEndpoint ae1 = new AuthorizationEndpoint(2, "146.48.85.179", 8080);
AuthorizationEndpoint ae2 = new AuthorizationEndpoint(1, "146.48.85.179", 8080);
AuthorizationEndpoint ae3 = new AuthorizationEndpoint(3, "146.48.85.179", 8080);
AuthorizationEndpoint ae1 = new AuthorizationEndpoint("/myInfra" ,2, "146.48.85.179", 8080);
AuthorizationEndpoint ae2 = new AuthorizationEndpoint("/myInfra" ,1, "146.48.85.179", 8080);
AuthorizationEndpoint ae3 = new AuthorizationEndpoint("/myInfra", 3, "146.48.85.179", 8080);
AuthorizationEndpoint[] arr1 = new AuthorizationEndpoint[]{ae1, ae2, ae3};