1 package org.sapia.util.license; 2 3 import java.io.ByteArrayInputStream ; 4 import java.util.Date ; 5 6 import junit.framework.TestCase; 7 8 17 public class LicenseRegistrationTest extends TestCase{ 18 19 public LicenseRegistrationTest(String name){ 20 super(name); 21 } 22 23 public void testRegisterLicense() throws Exception { 24 LicenseRegistrationFactory fac = new LicenseRegistrationFactory(); 25 TestLicense license1 = new TestLicense(); 26 LicenseRegistration reg = fac.createRegistration("foo", license1, new Date (), new SystemTimeIdFactory()); 27 super.assertTrue(!reg.getLicenseRecord().isValid(null, fac.getSecurityFactory())); 28 TestLicense license2 = new TestLicense(); 29 license2.valid = true; 30 reg.registerNewLicense(license2, new Date (), fac.getSecurityFactory(), new SystemTimeIdFactory()); 31 super.assertTrue(reg.getLicenseRecord().isValid(null, fac.getSecurityFactory())); 32 } 33 34 public void testSerialization() throws Exception { 35 TestLicense license = new TestLicense(); 36 LicenseRegistrationFactory fac = new LicenseRegistrationFactory(); 37 license.valid = true; 38 LicenseRegistration reg = fac.createRegistration("foo", license, new Date (), new SystemTimeIdFactory()); 39 super.assertTrue(reg.getLicenseRecord().isValid(null, fac.getSecurityFactory())); 40 byte[] data = LicenseUtils.toBytes(reg); 41 reg = (LicenseRegistration)LicenseUtils.fromBytes(new ByteArrayInputStream (data)); 42 super.assertTrue(reg.getLicenseRecord().isValid(null, fac.getSecurityFactory())); 43 } 44 45 } 46 | Popular Tags |