@Test public void testClearPolicies() { DQPWorkContext message = new DQPWorkContext(); message.setSession(Mockito.mock(SessionMetadata.class)); Mockito.stub(message.getSession().getVdb()).toReturn(new VDBMetaData()); Map<String, DataPolicy> map = message.getAllowedDataPolicies(); map.put("role", Mockito.mock(DataPolicy.class)); // $NON-NLS-1$ assertFalse(map.isEmpty()); message.setSession(Mockito.mock(SessionMetadata.class)); Mockito.stub(message.getSession().getVdb()).toReturn(new VDBMetaData()); map = message.getAllowedDataPolicies(); assertTrue(map.isEmpty()); }
@Test public void testAnyAuthenticated() { DQPWorkContext message = new DQPWorkContext(); SessionMetadata mock = Mockito.mock(SessionMetadata.class); message.setSession(mock); VDBMetaData vdb = new VDBMetaData(); DataPolicyMetadata dpm = new DataPolicyMetadata(); dpm.setAnyAuthenticated(true); vdb.addDataPolicy(dpm); Mockito.stub(mock.getVdb()).toReturn(vdb); // unauthenticated Map<String, DataPolicy> map = message.getAllowedDataPolicies(); assertEquals(0, map.size()); // authenticated message = new DQPWorkContext(); Mockito.stub(mock.getSubject()).toReturn(new Subject()); message.setSession(mock); map = message.getAllowedDataPolicies(); assertEquals(1, map.size()); }