Code example for CodeSource

0
        CodeSource cs23 = new CodeSource(new URL("file:///*"), (Certificate[]) null);
 
        CodeSource cs30 = new CodeSource(new URL("file:-"), (Certificate[]) null);
        CodeSource cs31 = new CodeSource(new URL("file:/-"), (Certificate[]) null);
        CodeSource cs32 = new CodeSource(new URL("file://-"), (Certificate[]) null);
        CodeSource cs33 = new CodeSource(new URL("file:///-"), (Certificate[]) null);
 
        PolicyEntry pe0  = new PolicyEntry(null, null, null);
 
        PolicyEntry pe10 = new PolicyEntry(cs10, null, null);
        PolicyEntry pe11 = new PolicyEntry(cs11, null, null);
        PolicyEntry pe12 = new PolicyEntry(cs12, null, null);
        PolicyEntry pe13 = new PolicyEntry(cs13, null, null);
 
        PolicyEntry pe20 = new PolicyEntry(cs20, null, null);
        PolicyEntry pe21 = new PolicyEntry(cs21, null, null);
        PolicyEntry pe22 = new PolicyEntry(cs22, null, null);
        PolicyEntry pe23 = new PolicyEntry(cs23, null, null);
 
        PolicyEntry pe30 = new PolicyEntry(cs30, null, null);
        PolicyEntry pe31 = new PolicyEntry(cs31, null, null);
        PolicyEntry pe32 = new PolicyEntry(cs32, null, null);
        PolicyEntry pe33 = new PolicyEntry(cs33, null, null);
 
        assertTrue (pe0.impliesCodeSource(null));
        assertTrue (pe0.impliesCodeSource(cs10));
        assertTrue (pe0.impliesCodeSource(cs11));
        assertTrue (pe0.impliesCodeSource(cs12));
        assertTrue (pe0.impliesCodeSource(cs13));
        assertTrue (pe0.impliesCodeSource(cs20));
        assertTrue (pe0.impliesCodeSource(cs21));
        assertTrue (pe0.impliesCodeSource(cs22));
        assertTrue (pe0.impliesCodeSource(cs23));
        assertTrue (pe0.impliesCodeSource(cs30));
        assertTrue (pe0.impliesCodeSource(cs31));
        assertTrue (pe0.impliesCodeSource(cs32));
        assertTrue (pe0.impliesCodeSource(cs33));
 
        assertFalse(pe10.impliesCodeSource(null));
        assertTrue (pe10.impliesCodeSource(cs10));
        assertFalse(pe10.impliesCodeSource(cs11));
        assertTrue (pe10.impliesCodeSource(cs12));
        assertFalse(pe10.impliesCodeSource(cs13));
        assertTrue (pe10.impliesCodeSource(cs20));
        assertFalse(pe10.impliesCodeSource(cs21));
        assertFalse(pe10.impliesCodeSource(cs22));
        assertFalse(pe10.impliesCodeSource(cs23));
        assertTrue (pe10.impliesCodeSource(cs30));
        assertFalse(pe10.impliesCodeSource(cs31));
        assertFalse(pe10.impliesCodeSource(cs32));
        assertFalse(pe10.impliesCodeSource(cs33));
 
        assertFalse(pe11.impliesCodeSource(null));
        assertFalse(pe11.impliesCodeSource(cs10));
        assertTrue (pe11.impliesCodeSource(cs11));
        assertFalse(pe11.impliesCodeSource(cs12));
        assertTrue (pe11.impliesCodeSource(cs13));
        assertFalse(pe11.impliesCodeSource(cs20));
        assertFalse(pe11.impliesCodeSource(cs21));
        assertFalse(pe11.impliesCodeSource(cs22));
        assertFalse(pe11.impliesCodeSource(cs23));
        assertFalse(pe11.impliesCodeSource(cs30));
        assertFalse(pe11.impliesCodeSource(cs31));
        assertFalse(pe11.impliesCodeSource(cs32));
        assertFalse(pe11.impliesCodeSource(cs33));
 
        assertFalse(pe12.impliesCodeSource(null));
        assertTrue (pe12.impliesCodeSource(cs10));
        assertFalse(pe12.impliesCodeSource(cs11));
        assertTrue (pe12.impliesCodeSource(cs12));
        assertFalse(pe12.impliesCodeSource(cs13));
        assertTrue (pe12.impliesCodeSource(cs20));
        assertFalse(pe12.impliesCodeSource(cs21));
        assertFalse(pe12.impliesCodeSource(cs22));
        assertFalse(pe12.impliesCodeSource(cs23));
        assertTrue (pe12.impliesCodeSource(cs30));
        assertFalse(pe12.impliesCodeSource(cs31));
        assertFalse(pe12.impliesCodeSource(cs32));
        assertFalse(pe12.impliesCodeSource(cs33));
 
        assertFalse(pe13.impliesCodeSource(null));
        assertFalse(pe13.impliesCodeSource(cs10));
        assertTrue (pe13.impliesCodeSource(cs11));
        assertFalse(pe13.impliesCodeSource(cs12));
        assertTrue (pe13.impliesCodeSource(cs13));
        assertFalse(pe13.impliesCodeSource(cs20));
        assertFalse(pe13.impliesCodeSource(cs21));
        assertFalse(pe13.impliesCodeSource(cs22));
        assertFalse(pe13.impliesCodeSource(cs23));
        assertFalse(pe13.impliesCodeSource(cs30));
        assertFalse(pe13.impliesCodeSource(cs31));
        assertFalse(pe13.impliesCodeSource(cs32));
        assertFalse(pe13.impliesCodeSource(cs33));
 
        assertFalse(pe20.impliesCodeSource(null));
        assertTrue (pe20.impliesCodeSource(cs10));
        assertFalse(pe20.impliesCodeSource(cs11));
        assertTrue (pe20.impliesCodeSource(cs12));
        assertFalse(pe20.impliesCodeSource(cs13));
        assertTrue (pe20.impliesCodeSource(cs20));
        assertFalse(pe20.impliesCodeSource(cs21));
        assertFalse(pe20.impliesCodeSource(cs22));
        assertFalse(pe20.impliesCodeSource(cs23));
        assertTrue (pe20.impliesCodeSource(cs30));
        assertFalse(pe20.impliesCodeSource(cs31));
        assertFalse(pe20.impliesCodeSource(cs32));
        assertFalse(pe20.impliesCodeSource(cs33));
 
        assertFalse(pe21.impliesCodeSource(null));
        assertFalse(pe21.impliesCodeSource(cs10));
        assertTrue (pe21.impliesCodeSource(cs11));
        assertFalse(pe21.impliesCodeSource(cs12));
        assertTrue (pe21.impliesCodeSource(cs13));
        assertFalse(pe21.impliesCodeSource(cs20));
        assertTrue (pe21.impliesCodeSource(cs21));
        assertFalse(pe21.impliesCodeSource(cs22));
        assertTrue (pe21.impliesCodeSource(cs23));
        assertFalse(pe21.impliesCodeSource(cs30));
        assertTrue (pe21.impliesCodeSource(cs31));
        assertFalse(pe21.impliesCodeSource(cs32));
        assertTrue (pe21.impliesCodeSource(cs33));
 
        assertFalse(pe22.impliesCodeSource(null));
        assertFalse(pe22.impliesCodeSource(cs10));
        // assertFalse(pe22.impliesCodeSource(cs11)); 
        assertFalse(pe22.impliesCodeSource(cs12));
        // assertFalse(pe22.impliesCodeSource(cs13)); 
        assertFalse(pe22.impliesCodeSource(cs20));
        assertFalse(pe22.impliesCodeSource(cs21));
        assertTrue (pe22.impliesCodeSource(cs22));
        assertFalse(pe22.impliesCodeSource(cs23));
        assertFalse(pe22.impliesCodeSource(cs30));
        assertFalse(pe22.impliesCodeSource(cs31));
        assertTrue (pe22.impliesCodeSource(cs32));
        assertFalse(pe22.impliesCodeSource(cs33));
 
        assertFalse(pe23.impliesCodeSource(null));
        assertFalse(pe23.impliesCodeSource(cs10));
        assertTrue (pe23.impliesCodeSource(cs11));
        assertFalse(pe23.impliesCodeSource(cs12));
        assertTrue (pe23.impliesCodeSource(cs13));
        assertFalse(pe23.impliesCodeSource(cs20));
        assertTrue (pe23.impliesCodeSource(cs21));
        assertFalse(pe23.impliesCodeSource(cs22));
        assertTrue (pe23.impliesCodeSource(cs23));
        assertFalse(pe23.impliesCodeSource(cs30));
        assertTrue (pe23.impliesCodeSource(cs31));
        assertFalse(pe23.impliesCodeSource(cs32));
        assertTrue (pe23.impliesCodeSource(cs33));
 
        assertFalse(pe30.impliesCodeSource(null));
        assertTrue (pe30.impliesCodeSource(cs10));
        assertFalse(pe30.impliesCodeSource(cs11));
        assertTrue (pe30.impliesCodeSource(cs12));
        assertFalse(pe30.impliesCodeSource(cs13));
        assertTrue (pe30.impliesCodeSource(cs20));
        assertFalse(pe30.impliesCodeSource(cs21));
        assertFalse(pe30.impliesCodeSource(cs22));
        assertFalse(pe30.impliesCodeSource(cs23));
        assertTrue (pe30.impliesCodeSource(cs30));
        assertFalse(pe30.impliesCodeSource(cs31));
        assertFalse(pe30.impliesCodeSource(cs32));
        assertFalse(pe30.impliesCodeSource(cs33));
 
        assertFalse(pe31.impliesCodeSource(null));
        assertTrue (pe31.impliesCodeSource(cs10));
        assertTrue (pe31.impliesCodeSource(cs11));
        assertTrue (pe31.impliesCodeSource(cs12));
        assertTrue (pe31.impliesCodeSource(cs13));
        assertTrue (pe31.impliesCodeSource(cs20));
        assertTrue (pe31.impliesCodeSource(cs21));
        assertFalse(pe31.impliesCodeSource(cs22));
        assertTrue (pe31.impliesCodeSource(cs23));
        assertTrue (pe31.impliesCodeSource(cs30));
        assertTrue (pe31.impliesCodeSource(cs31));
        assertFalse(pe31.impliesCodeSource(cs32));
        assertTrue (pe31.impliesCodeSource(cs33));
 
        assertFalse(pe32.impliesCodeSource(null));
        assertFalse(pe32.impliesCodeSource(cs10));
        assertFalse(pe32.impliesCodeSource(cs11));
        assertFalse(pe32.impliesCodeSource(cs12));
        assertFalse(pe32.impliesCodeSource(cs13));
        assertFalse(pe32.impliesCodeSource(cs20));
        assertFalse(pe32.impliesCodeSource(cs21));
        assertFalse(pe32.impliesCodeSource(cs22));
        assertFalse(pe32.impliesCodeSource(cs23));
        assertFalse(pe32.impliesCodeSource(cs30));
        assertFalse(pe32.impliesCodeSource(cs31));
        assertTrue (pe32.impliesCodeSource(cs32));
        assertFalse(pe32.impliesCodeSource(cs33));
 
        assertFalse(pe33.impliesCodeSource(null));
        assertTrue (pe33.impliesCodeSource(cs10));
        assertTrue (pe33.impliesCodeSource(cs11));
        assertTrue (pe33.impliesCodeSource(cs12));
        assertTrue (pe33.impliesCodeSource(cs13));
        assertTrue (pe33.impliesCodeSource(cs20));
        assertTrue (pe33.impliesCodeSource(cs21));
        assertFalse(pe33.impliesCodeSource(cs22));
        assertTrue (pe33.impliesCodeSource(cs23));
        assertTrue (pe33.impliesCodeSource(cs30));
        assertTrue (pe33.impliesCodeSource(cs31));
        assertFalse(pe33.impliesCodeSource(cs32));
        assertTrue (pe33.impliesCodeSource(cs33));
    } 
 
    /** 
     * Null or empty set of Principals of PolicyEntry implies any Principals; 
     * otherwise tested set must contain all Principals of PolicyEntry.