package eu.stork.peps.test.simple; import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import junit.framework.Assert; import org.junit.Test; import org.opensaml.xml.parse.BasicParserPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.stork.peps.auth.commons.STORKLogoutRequest; import eu.stork.peps.auth.commons.STORKLogoutResponse; import eu.stork.peps.auth.engine.STORKSAMLEngine; import eu.stork.peps.exceptions.STORKSAMLEngineException; public class StorkLogoutResponseTest { /** The engines. */ private static STORKSAMLEngine engine = STORKSAMLEngine.getInstance("CONF1"); private static STORKSAMLEngine engine0 = STORKSAMLEngine.getInstance("CONF0"); private static STORKSAMLEngine engine2 = STORKSAMLEngine.getInstance("CONF2"); private static STORKSAMLEngine engine3 = STORKSAMLEngine.getInstance("CONF3"); public StorkLogoutResponseTest() { destination = "http://C-PEPS.gov.xx/PEPS/ColleagueRequest"; spUserId = "IS/IS/1234567890"; } /** The destination. */ private String destination; /** The user id. */ private String spUserId; /** The logout request. */ private static byte[] logoutRequest; /** The logout response. */ private static byte[] logoutResponse; /** The Constant LOG. */ private static final Logger LOG = LoggerFactory.getLogger(StorkLogoutResponseTest.class.getName()); /** Parser manager used to parse XML. */ private static BasicParserPool parser; static { parser = new BasicParserPool(); parser.setNamespaceAware(true); } /** * Test generate authentication request. * * @throws STORKSAMLEngineException * the STORKSAML engine exception */ @Test public final void testGenerateLogoutRequest() throws STORKSAMLEngineException { final STORKLogoutRequest request = new STORKLogoutRequest(); final STORKLogoutResponse response = new STORKLogoutResponse(); request.setDestination(destination); response.setDestination(destination); request.setSpProvidedId(spUserId); STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(request); STORKLogoutResponse res = engine0.generateSTORKLogoutResponse(req1, response); byte[] reqByte = res.getTokenSaml(); FileOutputStream output = null; try { output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/LogoutResponse.xml")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { output.write(reqByte); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertNotNull(reqByte); } /** * Test generate authentication request. * * @throws STORKSAMLEngineException * the STORKSAML engine exception */ @Test public final void testGenerateLogoutRequestFail() throws STORKSAMLEngineException { final STORKLogoutRequest request = new STORKLogoutRequest(); final STORKLogoutResponse response = new STORKLogoutResponse(); request.setDestination(destination); response.setDestination(destination); response.setStatusMessage("User not found."); response.setStatusCode("1234"); request.setSpProvidedId(spUserId); STORKLogoutRequest req1 = engine0.generateSTORKLogoutRequest(request); STORKLogoutResponse res = engine0.generateSTORKLogoutResponseFail(req1, response); byte[] reqByte = res.getTokenSaml(); FileOutputStream output = null; try { output = new FileOutputStream(new File(System.getProperty("user.dir") + "/src/test/resources/data/eu/stork/STORKSAMLEngine/LogoutResponseFail.xml")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { output.write(reqByte); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertNotNull(reqByte); } }