Java tutorial
/*************************************************************************** * Copyright 2012 TXT e-solutions SpA * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * This work was performed within the IoT_at_Work Project * and partially funded by the European Commission's * 7th Framework Programme under the research area ICT-2009.1.3 * Internet of Things and enterprise environments. * * Authors: * Donato Andrisani (TXT e-solutions SpA) * * Contributors: * Domenico Rotondi (TXT e-solutions SpA) **************************************************************************/ package it.txt.access.capability.revocation.test; import static org.junit.Assert.*; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.nio.channels.ShutdownChannelGroupException; import java.security.GeneralSecurityException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Enumeration; import java.util.List; import java.util.Properties; import javax.security.auth.login.Configuration; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import iotAtWork.RevServApplication; import it.txt.access.capability.commons.schema.CapabilityNamespacesMapper; import it.txt.access.capability.commons.schema.factory.CapabilitySchemasLoader; import it.txt.access.capability.commons.schema.validation.CapabilitySchemaValidationHandlerException; import it.txt.access.capability.commons.signer.X509DocumentSigner; import it.txt.access.capability.commons.utils.XMLPrinter; import it.txt.access.capability.factory.CapabilitySchemaFactory; import it.txt.access.capability.factory.CapabilitySchemaFactoryException; import it.txt.access.capability.revocation.CapabilityRevocationType; import it.txt.access.capability.revocation.test.util.DataMapper; import it.txt.access.capability.schema.AccessRightsCapabilityType; import org.apache.http.entity.StringEntity; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.w3c.dom.Document; import com.orientechnologies.orient.client.remote.OServerAdmin; import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.db.ODatabase; import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; import com.orientechnologies.orient.core.record.impl.ODocument; import com.orientechnologies.orient.core.sql.OCommandSQL; import database.Constants; import pendingRevocationsManagement.PendingRevocationsManagement; import pendingRevocationsManagement.RevocationOutCome; import pendingRevocationsManagement.StatusCode; import revCreation.CreatedTokens; import revCreation.RevocationCreationByHand; import revServTest.IoTTestForPOST; import revServTest.IoTTestForPUT; import static revServTest.IoTTestForPOST.readFileAsString; public class RevocationServiceTest { private Configuration configuration; DataMapper create; RevocationCreationByHand creator; public RevocationServiceTest() { // TODO Auto-generated constructor stub } @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { setConfigurationData("config/pathRevocation.properties"); RevServApplication.main(null); create = new DataMapper(); create.clearAll(); } @After public void tearDown() throws Exception { } @Test public void testPost() throws UnsupportedEncodingException, IOException, JAXBException, ParserConfigurationException, NullPointerException, CapabilitySchemaFactoryException, CapabilitySchemaValidationHandlerException, DatatypeConfigurationException, GeneralSecurityException, InterruptedException { IoTTestForPOST testa = new IoTTestForPOST(); System.out.println("**********************************************************"); System.out.println("* CRP450 : CERTIFCATo *"); System.out.println("**********************************************************"); StringEntity input = new StringEntity(readFileAsString(System.getProperty("REVOCATION_FIRST"))); String result = testa.testPost(input); assertEquals(StatusCode.CRP450, result); System.out.println("**********************************************************"); System.out.println("* CRP451 : MISSING ID *"); System.out.println("**********************************************************"); StringEntity input0 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP451"))); String result0 = testa.testPost(input0); assertEquals(StatusCode.CRP451, result0); System.out.println("**********************************************************"); System.out.println("* CRP452 : MISSING ISSUER *"); System.out.println("**********************************************************"); StringEntity input1 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP452"))); String result1 = testa.testPost(input1); assertEquals(StatusCode.CRP452, result1); System.out.println("************************************************************************************"); System.out.println("*CRP453 : BAD ISSUER(the capRev issuer must be the subject of the authorising auCap*"); System.out.println("************************************************************************************"); StringEntity input2 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP453"))); String result2 = testa.testPost(input2); assertEquals(StatusCode.CRP453, result2); System.out.println("************************************************************************************"); System.out.println("* CRP454 : BAD AUTHORISING CAPABILITY(w.r.t. the syntactic validity *"); System.out.println("************************************************************************************"); StringEntity input3 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP454"))); String result3 = testa.testPost(input3); assertEquals(StatusCode.CRP454, result3); // // // // System.out.println("************************************************************************************"); // // // // // System.out.println("* CRP455 : BAD SIGNER (the capRev issuer must be the certificate signer) *"); // // // // // System.out.println("************************************************************************************"); // System.out.println("************************************************************************************"); System.out.println("* CRP456 : BAD VALIDITY TIME FRAME *"); System.out.println("************************************************************************************"); StringEntity input5 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP456"))); String result5 = testa.testPost(input5); assertEquals(StatusCode.CRP456, result5); System.out.println( "********************************************************************************************************************"); System.out.println( "*CRP457 : BAD REVOKED (this happens when the revoked auCap is the same revocation or resolving its pending status)*"); System.out.println( "********************************************************************************************************************"); StringEntity input6 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP457"))); String result6 = testa.testPost(input6); assertEquals(StatusCode.CRP457, result6); System.out.println("************************************************************************************"); System.out.println("* CRP458 : EXIPERED AUTHORISING CAPABILITY *"); System.out.println("************************************************************************************"); //create two capability with the String revID = null; try { // Required initialization CapabilitySchemasLoader loader = new CapabilitySchemasLoader(null); String schemasPath = System.getProperty("PATH_CAPABILITY_SCHEMA"); loader.loadCapabilityEntities(schemasPath); CapabilitySchemaFactory.getInstance(schemasPath); creator = new RevocationCreationByHand(); creator.setAuthorisingCapability(new File(System.getProperty("AUCAP_CRP458"))); creator.setAuthorisingCapabilityExpiration(new Date(new Date().getTime() + 2000)); creator.setCertificatePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setKeystore(new File(System.getProperty("KEYSTORE"))); creator.setKeystorePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setNotificationEmail("donato.andrisani@network.txtgroup.com"); creator.setReason("Why? Because..."); creator.setRevocationScope("ALL"); creator.setRevokedCapability(new File(System.getProperty("REVCAP_CRP458"))); creator.setRevokedCapabilityExpiration(new Date(new Date().getTime() + 10000)); creator.setRevokedSinceDateTime(new Date()); CreatedTokens tokens = creator.createRevocation(); JAXBContext context = JAXBContext.newInstance(AccessRightsCapabilityType.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); System.out.println("#####----- Modified authorising capability -----#####"); Document xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getAuthorisingCapability(), xmlDocument); assertTrue("The signature of the authorising capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); System.out.println("#####----- Modified revoked capability -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevokedCapability(), xmlDocument); assertTrue("The signature of the revoked capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); context = JAXBContext.newInstance(CapabilityRevocationType.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); System.out.println("#####----- Revocation -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevocationToken(), xmlDocument); assertTrue("The signature of the revocation is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####"); DataMapper insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getAuthorisingCapability()); DataMapper insertCapability1 = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getRevokedCapability()); context = JAXBContext.newInstance(CapabilityRevocationType.class); revID = tokens.getRevocationToken().getRevocationID(); Writer writer = new FileWriter( "D:/PC-DONATO/workspace/RevocationService/revocationTest/revocationPOSTTest/output_458.xml"); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); try { marshaller.marshal(tokens.getRevocationToken(), writer); System.out.println("CREATO FILE"); } finally { writer.close(); } } catch (JAXBException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (CapabilitySchemaFactoryException e) { e.printStackTrace(); } catch (CapabilitySchemaValidationHandlerException e) { e.printStackTrace(); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } catch (GeneralSecurityException e) { e.printStackTrace(); } StringEntity input7 = new StringEntity(readFileAsString(System.getProperty("OUTPUT_458"))); String result7 = testa.testPost(input7); Thread.sleep(4000); PendingRevocationsManagement p = new PendingRevocationsManagement(); p.processPendingCapabilityRevocation(); ODatabaseDocumentTx capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; List<ODocument> rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); ODocument element = rev.get(0); assertEquals(element.field(Constants.STATUS), "REJECTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP458); ODatabaseDocumentTx auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelPen = "select statusCode, status, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; List<ODocument> pen = auCapDb.command(new OCommandSQL(querySelPen)).execute(); ODocument element0 = pen.get(0); assertEquals(element0.field(Constants.STATUS), "REJECTED"); assertEquals(element0.field(Constants.STATUS_CODE), StatusCode.CRP458); assertNotNull(element0.field(Constants.RESOLVED_ON)); create.clearAll(); System.out.println("************************************************************************************"); System.out.println("* CRP459 : EXPIRED REVOKED CAPABILITY *"); System.out.println("************************************************************************************"); try { // Required initialization CapabilitySchemasLoader loader = new CapabilitySchemasLoader(null); String schemasPath = System.getProperty("PATH_CAPABILITY_SCHEMA"); loader.loadCapabilityEntities(schemasPath); CapabilitySchemaFactory.getInstance(schemasPath); creator = new RevocationCreationByHand(); creator.setAuthorisingCapability(new File(System.getProperty("AUCAP_CRP458"))); creator.setAuthorisingCapabilityExpiration(new Date(new Date().getTime() + 10000)); creator.setCertificatePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setKeystore(new File(System.getProperty("KEYSTORE"))); creator.setKeystorePsw(new char[] { 's', 'y', 's', 'm', 'g', 'r' }); creator.setNotificationEmail("alice@acme.com"); creator.setReason("Why? Because..."); creator.setRevocationScope("ALL"); creator.setRevokedCapability(new File(System.getProperty("REVCAP_CRP458"))); creator.setRevokedCapabilityExpiration(new Date(new Date().getTime() + 1000)); creator.setRevokedSinceDateTime(new Date()); CreatedTokens tokens = creator.createRevocation(); JAXBContext context = JAXBContext.newInstance(AccessRightsCapabilityType.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); System.out.println("#####----- Modified authorising capability -----#####"); Document xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getAuthorisingCapability(), xmlDocument); assertTrue("The signature of the authorising capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); System.out.println("#####----- Modified revoked capability -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevokedCapability(), xmlDocument); assertTrue("The signature of the revoked capability is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####\n\n"); context = JAXBContext.newInstance(CapabilityRevocationType.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); System.out.println("#####----- Revocation -----#####"); xmlDocument = docBuilder.newDocument(); marshaller.marshal(tokens.getRevocationToken(), xmlDocument); assertTrue("The signature of the revocation is not valid!", X509DocumentSigner.verifyXMLElementSign(xmlDocument.getDocumentElement())); System.out.println(XMLPrinter.printDocumentElement(xmlDocument.getDocumentElement(), true)); System.out.println("#####--------------- ---------------#####"); OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(false); OGlobalConfiguration.CACHE_LEVEL1_ENABLED.setValue(false); DataMapper insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getAuthorisingCapability()); DataMapper insertCapability1 = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), tokens.getRevokedCapability()); context = JAXBContext.newInstance(CapabilityRevocationType.class); revID = tokens.getRevocationToken().getRevocationID(); Writer writer = new FileWriter( "D:/PC-DONATO/workspace/RevocationService/revocationTest/revocationPOSTTest/output_459.xml"); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE); marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CapabilityNamespacesMapper()); try { marshaller.marshal(tokens.getRevocationToken(), writer); System.out.println("CREATO FILE"); } finally { writer.close(); } } catch (JAXBException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (CapabilitySchemaFactoryException e) { e.printStackTrace(); } catch (CapabilitySchemaValidationHandlerException e) { e.printStackTrace(); } catch (DatatypeConfigurationException e) { e.printStackTrace(); } catch (GeneralSecurityException e) { e.printStackTrace(); } StringEntity input8 = new StringEntity(readFileAsString(System.getProperty("OUTPUT_459"))); String result8 = testa.testPost(input8); Thread.sleep(5000); // PendingRevocationsManagement p = new PendingRevocationsManagement(); p.processPendingCapabilityRevocation(); capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); element = rev.get(0); assertEquals(element.field(Constants.STATUS), "REJECTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP459); auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelPen = "select statusCode, status, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '" + revID + "'"; pen = auCapDb.command(new OCommandSQL(querySelPen)).execute(); element0 = pen.get(0); assertEquals(element0.field(Constants.STATUS), "REJECTED"); assertEquals(element0.field(Constants.STATUS_CODE), StatusCode.CRP459); assertNotNull(element0.field(Constants.RESOLVED_ON)); assertEquals(StatusCode.CRP459, RevocationOutCome.code); create.clearAll(); System.out.println("************************************************************************************"); System.out.println("* CRP400 : BAD REVOCATION (w.r.t. the compliance with the XML SCHEMA) *"); System.out.println("************************************************************************************"); StringEntity input9 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP400"))); String result9 = testa.testPost(input9); assertEquals(StatusCode.CRP400, result9); System.out.println( "**********************************************************************************************************"); System.out.println( "*CRP403 : FORBIDDEN(AFTER RESOLUTION: the authorising auCAp has not the right thr revoke the given auCap)*"); System.out.println( "**********************************************************************************************************"); StreamSource xml = new StreamSource(System.getProperty("CAPABILITY1")); AccessRightsCapabilityType aucap = unMarshall(xml); DataMapper insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); xml = new StreamSource(System.getProperty("CAPABILITY2")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); StringEntity input10 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP403"))); String result10 = testa.testPost(input10); Thread.sleep(4000); p.processPendingCapabilityRevocation(); assertEquals(StatusCode.CRP403, RevocationOutCome.code); insertCapability.clearAll(); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP201 : ACCEPTED (side POST) *"); System.out.println( "**********************************************************************************************************"); StringEntity input11 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); String result11 = testa.testPost(input11); assertEquals(StatusCode.CRP202, result11); create.clearAll(); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP409 : DUPLICATED *"); System.out.println( "**********************************************************************************************************"); StringEntity prov = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP409"))); String test = testa.testPost(prov); assertEquals(StatusCode.CRP202, test); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP201 : ACCEPTED (side RESOLUTION PENDING) *"); System.out.println( "**********************************************************************************************************"); xml = new StreamSource(System.getProperty("CAPABILITY22")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); xml = new StreamSource(System.getProperty("CAPABILITY33")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); input11 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); result11 = testa.testPost(input11); Thread.sleep(4000); p.processPendingCapabilityRevocation(); assertEquals(StatusCode.CRP201, RevocationOutCome.code); capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); element = rev.get(0); assertEquals(element.field(Constants.STATUS), "ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP201); auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); String queryPend = "select statusCode, status, capabilityID, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; List<ODocument> res = auCapDb.command(new OCommandSQL(queryPend)).execute(); ODocument elem = res.get(0); String Revoked_Index_Sel = "select from index:" + Constants.REVOKED_INDEX_NAME; List<ODocument> Revoked_Index = auCapDb.command(new OCommandSQL(Revoked_Index_Sel)).execute(); assertEquals(elem.field(Constants.STATUS), "ACCEPTED"); assertEquals(elem.field(Constants.STATUS_CODE), StatusCode.CRP201); assertNotNull(elem.field(Constants.RESOLVED_ON)); assertNotNull(Revoked_Index); System.out.println( "**********************************************************************************************************"); System.out.println( "* CRP200 : WAS ACCEPTED *"); System.out.println( "**********************************************************************************************************"); xml = new StreamSource(System.getProperty("CAPABILITY11")); aucap = unMarshall(xml); insertCapability = new DataMapper(System.getProperty("CAPABILITY_DB_PATH"), System.getProperty("USER"), System.getProperty("PSW"), aucap); StringEntity input12 = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP200"))); String result12 = testa.testPost(input12); Thread.sleep(5000); p.processPendingCapabilityRevocation(); assertEquals(StatusCode.CRP200, RevocationOutCome.code); capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); querySelRev = "select statusCode, status from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_a1192622c7f69af47a906ef7ef1a4b15'"; rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); element = rev.get(0); assertEquals(element.field(Constants.STATUS), "WAS_ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.CRP200); auCapDb = new ODatabaseDocumentTx(Constants.capabilityDBUrl).open(Constants.iUserName, Constants.iUserPassword); queryPend = "select statusCode, status, capabilityID, resolvedOn from " + Constants.PENDING_CLASS + " where " + Constants.REVOCATION_ID + " = '_a1192622c7f69af47a906ef7ef1a4b15'"; res = auCapDb.command(new OCommandSQL(queryPend)).execute(); elem = res.get(0); assertEquals(elem.field(Constants.STATUS), "WAS_ACCEPTED"); assertEquals(elem.field(Constants.STATUS_CODE), StatusCode.CRP200); assertNotNull(elem.field(Constants.RESOLVED_ON)); // System.out.println("**********************************************************************************************************"); // System.out.println("* CRP500 : INTERNAL SERVER ERROR *"); // System.out.println("**********************************************************************************************************"); // // OServerAdmin admin = new // OServerAdmin(System.getProperty("REVOCATION_DB_PATH_ERRATO")); // admin.connect(Constants.iUserName, Constants.iUserPassword); // admin.dropDatabase(); // // StringEntity input13 = new // StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP500"))); // String result13 = testa.testPost(input13); // assertEquals(StatusCode.CRP500, result13); create.clearAll(); } @Test public void testPut() throws UnsupportedEncodingException, IOException, JAXBException { IoTTestForPUT test = new IoTTestForPUT(); System.out.println("**********************************************************"); System.out.println("* NPR400 : BAD NOTIFICATION (at least one missing element*"); System.out.println("**********************************************************"); StringEntity input0 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR400"))); String url0 = System.getProperty("URL_NPR400"); String result0 = test.testPut(url0, input0); assertEquals(StatusCode.NPR400, result0); System.out.println("**********************************************************"); System.out.println("* NPR404 : REVOCATION NOT FOUND *"); System.out.println("**********************************************************"); StringEntity input1 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR404"))); String url1 = System.getProperty("URL_NPR404"); String result1 = test.testPut(url1, input1); assertEquals(StatusCode.NPR404, result1); System.out.println("**********************************************************"); System.out.println("* NPR450 : BAD REVOCATION PROCESSING STATUS CODE *"); System.out.println("**********************************************************"); StringEntity input2 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR450"))); String url2 = System.getProperty("URL_NPR450"); String result2 = test.testPut(url2, input2); assertEquals(StatusCode.NPR450, result2); System.out.println("**********************************************************"); System.out.println("* NPR451 : BAD RESOLUTION ISTANT *"); System.out.println("**********************************************************"); StringEntity input3 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR451"))); String url3 = System.getProperty("URL_NPR451"); String result3 = test.testPut(url3, input3); assertEquals(StatusCode.NPR451, result3); System.out.println("**********************************************************"); System.out.println("* NPR452 : BAD REVOCATION PROCESSING STATUS *"); System.out.println("**********************************************************"); StringEntity input4 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR452"))); String url4 = System.getProperty("URL_NPR452"); String result4 = test.testPut(url4, input4); assertEquals(StatusCode.NPR452, result4); System.out.println("**********************************************************"); System.out.println("* NPR200 : OK *"); System.out.println("**********************************************************"); IoTTestForPOST testa = new IoTTestForPOST(); StringEntity inp = new StringEntity(readFileAsString(System.getProperty("REVOCATION_CRP201"))); String res = testa.testPost(inp); assertNotNull(res); DataMapper delete = new DataMapper(); delete.clearPendingIndex(); StringEntity input5 = new StringEntity(readFileAsString(System.getProperty("NOTIFICATION_NPR200"))); String url5 = System.getProperty("URL_NPR200"); String result5 = test.testPut(url5, input5); assertEquals(StatusCode.NPR200, result5); ODatabaseDocumentTx capRevDb = new ODatabaseDocumentTx(Constants.revocationDBUrl).open(Constants.iUserName, Constants.iUserPassword); String querySelRev = "select statusCode, status, processedOn from " + Constants.REVOCATION_CLASS + " where " + Constants.REVOCATION_ID + " = '_e49af3ee828b03a32c39df493cf4c674'"; List<ODocument> rev = capRevDb.command(new OCommandSQL(querySelRev)).execute(); ODocument element = rev.get(0); assertEquals(element.field(Constants.STATUS), "ACCEPTED"); assertEquals(element.field(Constants.STATUS_CODE), StatusCode.NPR200); String processedOn = null; try { XMLGregorianCalendar cal = DatatypeFactory.newInstance() .newXMLGregorianCalendar("2012-03-30T09:35:58.011+02:00"); Date gCal = cal.toGregorianCalendar().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); processedOn = sdf.format(gCal.getTime()); } catch (Exception e) { } String date = null; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); date = sdf.format(element.field(Constants.PROCESSED_ON)); } catch (Exception e) { } assertEquals(date, processedOn); } public Configuration getConfiguration() { return configuration; } @SuppressWarnings("rawtypes") private static void setConfigurationData(String path) { try { // Build a properties file for student. File file = new File(path); file.createNewFile(); Properties properties = new Properties(); properties.load(new FileInputStream(file)); Enumeration e = properties.keys(); while (e.hasMoreElements()) { Object obj = e.nextElement(); System.setProperty(obj.toString(), properties.getProperty(obj.toString())); } } catch (IOException ex) { System.out.println(ex.toString()); } } public AccessRightsCapabilityType unMarshall(StreamSource xml) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(AccessRightsCapabilityType.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); AccessRightsCapabilityType AuCap = (AccessRightsCapabilityType) jaxbUnmarshaller.unmarshal(xml); // new StreamSource("file.xml") return AuCap; } }