Project

General

Profile

« Previous | Next » 

Revision 5342

Added by berkley almost 14 years ago

adding test for getSystemMetadata. a bit of refactoring.

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
132 132
	        AuthToken token = getToken();
133 133
	        //run create
134 134
	        Identifier id = createDoc(token);
135
            
136
            //try to get the same doc then compare them
137
            InputStream gotDocStream = cs.get(token, id);
138
            StringBuffer sb = new StringBuffer();
139
            byte[] b = new byte[1024];
140
            int numread = gotDocStream.read(b, 0, 1024);
141
            while(numread != -1)
142
            {
143
                sb.append(new String(b, 0, numread));
144
                numread = gotDocStream.read(b, 0, 1024);
145
            }
146
            
147
            String gotDoc = sb.toString();
135
            String gotDoc = getDoc(token, id);
148 136
            System.out.println("got doc: " + gotDoc);
149 137
            assertTrue(gotDoc.trim().equals(testDoc.trim()));
150 138
        }
......
173 161
		assertTrue(1 == 1);
174 162
	}
175 163
	
164
	/**
165
	 * get a doc from metacat using CrudService.get()
166
	 */
167
	private String getDoc(AuthToken token, Identifier id)
168
	  throws Exception
169
	{
170
	    CrudService cs = CrudService.getInstance();
171
	    //try to get the same doc then compare them
172
        InputStream gotDocStream = cs.get(token, id);
173
        StringBuffer sb = new StringBuffer();
174
        byte[] b = new byte[1024];
175
        int numread = gotDocStream.read(b, 0, 1024);
176
        while(numread != -1)
177
        {
178
            sb.append(new String(b, 0, numread));
179
            numread = gotDocStream.read(b, 0, 1024);
180
        }
181
        
182
        return sb.toString();
183
	}
184
	
185
	/**
186
	 * return a test document
187
	 */
176 188
	private String getTestDoc()
177 189
	{
178 190
	    return "<?xml version=\"1.0\"?><test></test>\n";
......
202 214
	}
203 215
	
204 216
	/**
205
	 * create a doc and return its id
217
	 * create a doc using CrudService.create() and return its id
206 218
	 */
207 219
	private Identifier createDoc(AuthToken token) throws Exception
208 220
	{

Also available in: Unified diff