1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.it;
36
37 import java.text.MessageFormat;
38
39 import javax.security.auth.login.LoginContext;
40
41 import junit.framework.Assert;
42
43 import org.apache.log4j.Logger;
44 import org.ogf.graap.wsag.api.client.AgreementClient;
45 import org.ogf.graap.wsag.api.client.AgreementFactoryClient;
46 import org.ogf.graap.wsag.api.client.AgreementFactoryRegistryClient;
47 import org.ogf.graap.wsag.client.AgreementFactoryRegistryLocator;
48 import org.ogf.graap.wsag.security.core.KeystoreProperties;
49 import org.ogf.graap.wsag.security.core.keystore.KeystoreLoginContext;
50 import org.w3.x2005.x08.addressing.EndpointReferenceType;
51
52
53
54
55
56
57
58
59
60 public abstract class AbstractIntegrationTest extends WsagTestCase
61 {
62
63 private static final Logger LOG = Logger.getLogger( AbstractIntegrationTest.class );
64
65
66
67
68 private static String url = "http://127.0.0.1:8080/wsag4j";
69
70
71
72
73 public static String getUrl()
74 {
75 return url;
76 }
77
78
79
80
81
82 public static void setUrl( String url )
83 {
84 AbstractIntegrationTest.url = url;
85 }
86
87
88
89
90 public static final int EXPECTED_FACTORIES = 2;
91
92
93
94
95 public static final int EXPECTED_TEMPLATES_FACTORY_1 = 4;
96
97
98
99
100 public static final int EXPECTED_TEMPLATES_FACTORY_2 = 2;
101
102 static
103 {
104 String gatewayURL = System.getProperty( "wsag4j.gateway.address" );
105 if ( gatewayURL != null )
106 {
107 LOG.info( "Gateway address was set via SystemPorperties: " + gatewayURL );
108 url = gatewayURL;
109 }
110 else
111 {
112 LOG.info( "Gateway address was not set via SystemPorperties." );
113 }
114 }
115
116
117
118
119
120 protected AbstractIntegrationTest( String name )
121 {
122 super( name );
123 }
124
125
126
127
128
129
130
131 protected void setUp() throws Exception
132 {
133 super.setUp();
134
135 EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
136 epr.addNewAddress().setStringValue( url );
137
138 AgreementFactoryRegistryClient registry = null;
139 AgreementFactoryClient[] factories = null;
140
141 try
142 {
143 registry = AgreementFactoryRegistryLocator.getFactoryRegistry( epr, getLoginContext() );
144 factories = registry.listAgreementFactories();
145 }
146 catch ( Exception ex )
147 {
148 Assert.fail( "Failed to initialize factory list. " + ex.getMessage() );
149 }
150
151
152
153
154 try
155 {
156 for ( int i = 0; i < factories.length; i++ )
157 {
158 AgreementClient[] agreements = factories[i].listAgreements();
159 for ( int j = 0; j < agreements.length; j++ )
160 {
161 agreements[j].destroy();
162 }
163 }
164 }
165 catch ( Exception e )
166 {
167 String message =
168 MessageFormat.format( "Error while cleaning up existing agreement resources. Error: {0}",
169 new Object[] { e.getMessage() } );
170 LOG.error( message );
171 throw e;
172 }
173 }
174
175
176
177
178 protected void tearDown() throws Exception
179 {
180 super.tearDown();
181 }
182
183
184
185
186
187 public static AgreementFactoryClient[] getAgreementFactoryClients()
188 {
189 AgreementFactoryClient[] factories = null;
190 try
191 {
192
193 LoginContext loginContext = AbstractIntegrationTest.getLoginContext();
194
195
196 EndpointReferenceType epr = EndpointReferenceType.Factory.newInstance();
197 epr.addNewAddress().setStringValue( AbstractIntegrationTest.url );
198
199 AgreementFactoryRegistryClient registry =
200 AgreementFactoryRegistryLocator.getFactoryRegistry( epr, loginContext );
201 factories = registry.listAgreementFactories();
202
203 }
204 catch ( Exception ex )
205 {
206 LOG.error( ex );
207 }
208
209 return factories;
210 }
211
212
213
214
215
216
217
218 public static LoginContext getLoginContext() throws Exception
219 {
220
221
222
223 LOG.info( "Create Keystore-LoginContext" );
224
225
226 KeystoreProperties properties = new KeystoreProperties();
227 properties.setKeyStoreAlias( "wsag4j-user" );
228 properties.setPrivateKeyPassword( "user@wsag4j" );
229
230 properties.setKeyStoreType( "JKS" );
231 properties.setKeystoreFilename( "/wsag4j-client-keystore.jks" );
232 properties.setKeystorePassword( "user@wsag4j" );
233
234 properties.setTruststoreType( "JKS" );
235 properties.setTruststoreFilename( "/wsag4j-client-keystore.jks" );
236 properties.setTruststorePassword( "user@wsag4j" );
237
238 LoginContext loginContext = new KeystoreLoginContext( properties );
239 loginContext.login();
240
241
242 return loginContext;
243 }
244 }