Project

General

Profile

« Previous | Next » 

Revision 7670

Added by Jing Tao almost 11 years ago

Add tests to test group and rightsholder.

View differences:

SolrQueryAccessFilterTest.java
60 60
      
61 61
      TestSuite suite = new TestSuite();
62 62
      suite.addTest(new SolrQueryAccessFilterTest("testPublicReadable"));
63
  
63
      suite.addTest(new SolrQueryAccessFilterTest("testOnlyUserReadable"));
64
      suite.addTest(new SolrQueryAccessFilterTest("testGroupReadable"));
65
      suite.addTest(new SolrQueryAccessFilterTest("testOnlyRightHolderReadable"));
64 66
      
65 67
      return suite;
66 68
      
......
100 102
        File object = new File(EMLFILE);
101 103
        SystemMetadata sysmeta = generateSystemMetadata(id, session.getSubject(), object , allowUsers);
102 104
        createObject(session, id, object, sysmeta);
105
        Thread.sleep(10000);
103 106
        Session querySession = getSession(Constants.SUBJECT_PUBLIC, null);
104
        Thread.sleep(10000);
105 107
        String resultId = query(querySession, id);
106
        assertTrue("In the testPublicReadable method, the query result should have the id "+id.getValue(), resultId.equals(id.getValue()));
107
        //session = getSession(CREATEUSER, null);
108
        assertTrue("In the testPublicReadable method, the query result should have the id "+id.getValue()+ " rather than "+resultId, resultId.equals(id.getValue()));
109
        Session querySession2 = getSession(QUERYUSER, null);
110
        String resultId2 = query(querySession2, id);
111
        assertTrue("In the testPublicReadable method, the query result should have the id "+id.getValue()+ " rather than "+resultId2, resultId2.equals(id.getValue()));
108 112
        archive(session, id);
109 113
    }
110 114
    
......
112 116
    /**
113 117
     * Test to query a document which can only be read by a specified user
114 118
     */
115
    public void testOnlyUserReadable() {
119
    public void testOnlyUserReadable() throws Exception {
120
        Thread.sleep(15000);
121
        Session session = getSession(CREATEUSER, null);
122
        Identifier id = generateIdentifier();
123
        String[] allowUsers = {QUERYUSER};
124
        File object = new File(EMLFILE);
125
        SystemMetadata sysmeta = generateSystemMetadata(id, session.getSubject(), object , allowUsers);
126
        createObject(session, id, object, sysmeta);
116 127
        
128
        Thread.sleep(10000);
129
        Session querySession = getSession(Constants.SUBJECT_PUBLIC, null);
130
        String resultId = query(querySession, id);
131
        assertTrue("In the testOnlyUserReadable method, the query result id should be null for the public rather than "+resultId, resultId == null);
132
        Session querySession2 = getSession(QUERYUSER, null);
133
        resultId = query(querySession2, id);
134
        assertTrue("In the testOnlyUserReadable method, the query result for the user "+QUERYUSER+" should have the id "+id.getValue()+" rather than "+resultId, resultId.equals(id.getValue()));
135
        archive(session, id);
117 136
    }
118 137
    
119 138
    /**
120 139
     * Test to query a document which can be read by a specified group
121 140
     */
122
    public void testGroupReadable() {
123
        
141
    public void testGroupReadable() throws Exception {
142
        Thread.sleep(15000);
143
        Session session = getSession(CREATEUSER, null);
144
        Identifier id = generateIdentifier();
145
        String[] allowUsers = {GROUP1, GROUP2};
146
        File object = new File(EMLFILE);
147
        SystemMetadata sysmeta = generateSystemMetadata(id, session.getSubject(), object , allowUsers);
148
        createObject(session, id, object, sysmeta);
149
        Thread.sleep(10000);
150
        Session querySession = getSession(Constants.SUBJECT_PUBLIC, null);
151
        String resultId = query(querySession, id);
152
        assertTrue("In the testGroupReadable method, the query result id should be null for the public ", resultId == null);
153
        Session querySession2 = getSession(QUERYUSER, null);
154
        resultId = query(querySession2, id);
155
        assertTrue("In the testGroupReadable method, the query result for the user "+QUERYUSER+" which doesn't belong to the group should be null ", resultId == null);
156
        String[]groups = {GROUP1};
157
        Session querySession3 = getSession(QUERYUSER, groups);
158
        resultId = query(querySession3, id);
159
        assertTrue("In the testGroupReadable method, the query result for the user "+QUERYUSER+" which belong to the group should have the id "+id.getValue(), resultId.equals(id.getValue()));
160
        archive(session, id);
124 161
    }
125 162
    
126 163
    
127 164
    /**
128 165
     * Test to query a document which only can be read by the rightHolder
129 166
     */
130
    public void testOnlyRightHolderReadable() {
131
        
167
    public void testOnlyRightHolderReadable() throws Exception {
168
        Thread.sleep(15000);
169
        Session session = getSession(CREATEUSER, null);
170
        Identifier id = generateIdentifier();
171
        String[] allowUsers = null;
172
        File object = new File(EMLFILE);
173
        SystemMetadata sysmeta = generateSystemMetadata(id, session.getSubject(), object , allowUsers);
174
        createObject(session, id, object, sysmeta);
175
        Thread.sleep(10000);
176
        Session querySession = getSession(Constants.SUBJECT_PUBLIC, null);
177
        String resultId = query(querySession, id);
178
        assertTrue("In the testOnlyRightHolderReadable method, the query result id should be null for the public ", resultId == null);
179
        Session querySession2 = getSession(QUERYUSER, null);
180
        resultId = query(querySession2, id);
181
        assertTrue("In the testOnlyRightHolderReadable method, the query result for the user "+QUERYUSER+" which doesn't belong to the group should be null.", resultId == null);
182
        String[]groups = {GROUP1};
183
        Session querySession3 = getSession(QUERYUSER, groups);
184
        resultId = query(querySession3, id);
185
        assertTrue("In the testOnlyRightHolderReadable method, the query result for the user "+QUERYUSER+" which belong to the group should be null.", resultId == null);
186
        Session querySession4 = getSession(CREATEUSER, groups);
187
        resultId = query(querySession4, id);
188
        assertTrue("In the testOnlyRightHolderReadable method, the query result for the creator "+CREATEUSER+" should be "+id.getValue(), id.getValue().equals(resultId));
189
        archive(session, id);
132 190
    }
133 191
    
134 192
    /*
......
211 269
     */
212 270
    private String query(Session session, Identifier id) throws Exception{
213 271
        String query = generateQuery(id.getValue());
214
        InputStream input = MNodeService.getInstance(request).query(SOLR, query);
272
        MNodeService service = MNodeService.getInstance(request);
273
        service.setSession(session);
274
        InputStream input = service.query(SOLR, query);
215 275
        return extractId(input);
216 276
    }
217 277
    

Also available in: Unified diff