コード例 #1
0
  /**
   * Test method for {@link
   * org.societies.privacytrust.privacyprotection.privacypolicy.PrivacyPolicyManager#inferPrivacyPolicy()}.
   */
  @Test
  public void testInferPrivacyPolicy() {
    String testTitle = new String("testInferPrivacyPolicy");
    LOG.info("[#" + testCaseNumber + "] " + testTitle);
    RequestPolicy expected = new RequestPolicy(new ArrayList<RequestItem>());
    RequestPolicy actual = null;
    try {
      actual =
          TestCase1244.privacyPolicyManager.inferPrivacyPolicy(
              PrivacyPolicyTypeConstants.CIS, null);
    } catch (PrivacyException e) {
      LOG.error("[#" + testCaseNumber + "] [Test PrivacyException] " + testTitle, e);
      fail("Privacy error");
    } catch (Exception e) {
      LOG.error("[#" + testCaseNumber + "] [Test Exception] " + testTitle, e);
      fail("Error");
    }

    // Modified by Rafik
    // before:
    // assertEquals(expected, actual);
    // After:
    assertEquals(
        "Privacy policy inferred not equals to the exepcted empty one",
        expected.toXMLString(),
        actual.toXMLString());
  }
コード例 #2
0
  /**
   * Test method for {@link
   * org.societies.privacytrust.privacyprotection.privacypolicy.PrivacyPolicyManager#fromXMLString(org.lang.String
   * privacyPolicy)}.
   */
  @Test
  public void testFromXml() {
    String testTitle = new String("testFromXml");
    LOG.info("[#" + testCaseNumber + "] " + testTitle);
    RequestPolicy privacyPolicy = null;
    try {
      privacyPolicy =
          TestCase1244.privacyPolicyManager.fromXMLString(
              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + cisPolicy.toXMLString());
    } catch (PrivacyException e) {
      LOG.error("[#" + testCaseNumber + "] [Test PrivacyException] " + testTitle, e);
      fail("Privacy error");
    } catch (Exception e) {
      LOG.error("[#" + testCaseNumber + "] [Test Exception] " + testTitle, e);
      fail("Error");
    }

    // Modified by Rafik
    // before:
    // assertEquals("Privacy policy generated not equal to the original policy", cisPolicy,
    // privacyPolicy);
    // After:
    assertEquals(
        "Privacy policy generated not equal to the original policy",
        cisPolicy.toXMLString(),
        privacyPolicy.toXMLString());
  }
コード例 #3
0
  /**
   * Test method for {@link
   * org.societies.privacytrust.privacyprotection.privacypolicy.PrivacyPolicyManager#getPrivacyPolicy(java.lang.String)}.
   */
  @Test
  public void testGetServicePrivacyPolicy() {
    String testTitle = new String("testGetServicePrivacyPolicy: add and retrieve a privacy policy");
    LOG.info("[#" + testCaseNumber + "] " + testTitle);
    RequestPolicy addedPrivacyPolicy = null;
    RequestPolicy privacyPolicy = null;
    boolean deleteResult = false;
    try {
      addedPrivacyPolicy = TestCase1244.privacyPolicyManager.updatePrivacyPolicy(servicePolicy);
      privacyPolicy = TestCase1244.privacyPolicyManager.getPrivacyPolicy(requestorService);
      deleteResult = TestCase1244.privacyPolicyManager.deletePrivacyPolicy(requestorService);
    } catch (PrivacyException e) {
      LOG.error("[#" + testCaseNumber + "] [Test PrivacyException] " + testTitle, e);
      fail("Privacy error");
    } catch (Exception e) {
      LOG.error("[#" + testCaseNumber + "] [Test Exception] " + testTitle, e);
      fail("Error");
    }
    assertNotNull("Privacy policy not added.", addedPrivacyPolicy);
    assertNotNull("Privacy policy retrieved is null, but it should not.", privacyPolicy);

    // Modified by Rafik
    // before:
    // assertEquals("Expected a privacy policy, but it what not the good one.", privacyPolicy,
    // addedPrivacyPolicy);
    // After:
    assertEquals(
        "Expected a privacy policy, but it what not the good one.",
        privacyPolicy.toXMLString(),
        addedPrivacyPolicy.toXMLString());
    assertTrue("Privacy policy not deleted.", deleteResult);
  }
コード例 #4
0
 /**
  * Test method for {@link
  * org.societies.privacytrust.privacyprotection.privacypolicy.PrivacyPolicyManager#deletePrivacyPolicy(java.lang.String)}.
  */
 @Test
 public void testDeleteCisPrivacyPolicyNotExisting() {
   String testTitle =
       new String("testDeleteCisPrivacyPolicyNotExisting: delete a non-existing privacy policy");
   LOG.info("[#" + testCaseNumber + "] " + testTitle);
   RequestPolicy privacyPolicy = null;
   boolean deleteResult = false;
   try {
     privacyPolicy = TestCase1244.privacyPolicyManager.getPrivacyPolicy(requestorCis);
     deleteResult = TestCase1244.privacyPolicyManager.deletePrivacyPolicy(requestorCis);
   } catch (PrivacyException e) {
     LOG.error("[#" + testCaseNumber + "] [Test PrivacyException] " + testTitle, e);
     fail("Privacy error");
   } catch (Exception e) {
     LOG.error("[#" + testCaseNumber + "] [Test Exception] " + testTitle, e);
     fail("Error");
   }
   assertNull("This privacy policy exists!", privacyPolicy);
   if (null != privacyPolicy) {
     LOG.info(privacyPolicy.toXMLString());
   }
   assertTrue("Privacy policy not deleted.", deleteResult);
 }
コード例 #5
0
 /**
  * Test method for {@link
  * org.societies.privacytrust.privacyprotection.privacypolicy.PrivacyPolicyManager#fromXMLString(org.lang.String
  * privacyPolicy)}.
  */
 @Test
 public void testToXml() {
   String testTitle = new String("testToXml");
   LOG.info("[#" + testCaseNumber + "] " + testTitle);
   String privacyPolicy = null;
   try {
     privacyPolicy = TestCase1244.privacyPolicyManager.toXMLString(cisPolicy);
   } catch (Exception e) {
     LOG.error("[#" + testCaseNumber + "] [Test Exception] " + testTitle, e);
     fail("Error");
   }
   assertEquals(
       "Privacy policy generated not equal to the original policy",
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + cisPolicy.toXMLString(),
       privacyPolicy);
 }
コード例 #6
0
  /**
   * Test method for {@link
   * org.societies.privacytrust.privacyprotection.privacypolicy.PrivacyPolicyManager#updatePrivacyPolicy(org.societies.api.internal.privacytrust.privacyprotection.model.privacypolicy.RequestPolicy)}.
   */
  @Test
  public void testUpdatesCisPrivacyPolicies() {
    String testTitle = new String("testUpdatePrivacyPolicy: update the same privacy policy");
    LOG.info("[#" + testCaseNumber + "] " + testTitle);
    RequestPolicy privacyPolicy1 = null;
    RequestPolicy privacyPolicy2 = null;
    RequestItem requestItem =
        new RequestItem(
            cisPolicy.getRequests().get(0).getResource(),
            cisPolicy.getRequests().get(0).getActions(),
            cisPolicy.getRequests().get(0).getConditions());
    List<RequestItem> requestItems = new ArrayList<RequestItem>();
    requestItems.add(requestItem);
    RequestPolicy cisPolicy2 = new RequestPolicy(requestItems);
    cisPolicy2.setRequestor(requestorCis);
    boolean deleteResult = false;
    try {
      privacyPolicy1 = TestCase1244.privacyPolicyManager.updatePrivacyPolicy(cisPolicy);
      privacyPolicy2 = TestCase1244.privacyPolicyManager.updatePrivacyPolicy(cisPolicy2);
      deleteResult = TestCase1244.privacyPolicyManager.deletePrivacyPolicy(requestorCis);
    } catch (PrivacyException e) {
      LOG.error("[#" + testCaseNumber + "] [Test PrivacyException] " + testTitle, e);
      fail("Privacy error");
    } catch (Exception e) {
      LOG.error("[#" + testCaseNumber + "] [Test Exception] " + testTitle, e);
      fail("Error");
    }

    // Modified by Rafik
    // before:
    // assertEquals("Privacy policy not created", cisPolicy, privacyPolicy1);
    // After:
    assertEquals(
        "Privacy policy not created", cisPolicy.toXMLString(), privacyPolicy1.toXMLString());

    // Modified by Rafik
    // before:
    // assertEquals("Privacy policy not updated", cisPolicy2, privacyPolicy2);
    // After:
    assertEquals(
        "Privacy policy not updated", cisPolicy2.toXMLString(), privacyPolicy2.toXMLString());

    // Modified by Rafik
    // before:
    // assertFalse("Same privacy policies but it should not",
    // privacyPolicy1.equals(privacyPolicy2));
    // After:
    assertFalse(
        "Same privacy policies but it should not",
        privacyPolicy1.toXMLString().equals(privacyPolicy2.toXMLString()));

    assertTrue("Privacy policy not deleted.", deleteResult);
  }