Project

General

Profile

« Previous | Next » 

Revision 5461

Added by berkley over 14 years ago

fixed error where insert/update errors were not getting caught as exceptions

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
100 100
		suite.addTest(new CrudServiceTest("testGetLogRecords"));
101 101
		suite.addTest(new CrudServiceTest("testChecksumError"));
102 102
		suite.addTest(new CrudServiceTest("testPublicAccess"));
103
		suite.addTest(new CrudServiceTest("testFailedCreate"));
103 104
		return suite;
104 105
	}
105 106
	
106 107
	/**
108
	 * insert an invalid document and make sure create fails and does not
109
	 * leave any artifacts behind
110
	 */
111
	public void testFailedCreate()
112
	{
113
	    try
114
	    {
115
	        String invalidDoc = "<xxx></yyy>";
116
	        System.out.println("trying to insert doc " + invalidDoc);
117
	        CrudService cs = CrudService.getInstance();
118
            AuthToken token = getToken();
119
            //run create
120
            try
121
            {
122
                Identifier id = createDoc(token, invalidDoc);
123
                fail("Should have thrown an exception.");
124
            }
125
            catch(Exception e)
126
            {
127
                //e.printStackTrace();
128
            }
129
            
130
	    }
131
	    catch(Exception e)
132
	    {
133
	        fail("unexpected exception in testFailedCreate: " + e.getMessage());
134
	    }
135
	}
136
	
137
	/**
107 138
	 * test to make sure that get and listObjects methods are publicly accessible
108 139
	 */
109 140
	public void testPublicAccess()
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
1005 1005
            //parse the stream here.  This has the disavantage of putting the
1006 1006
            //stream into memory.
1007 1007
            String s = streamToString(request.getInputStream());
1008
            System.out.println("s: " + s);
1008 1009
            String searchString = "Content-Disposition: attachment; filename=systemmetadata";
1009 1010
            String endString = "------=_Part";
1010 1011
            int searchStringIndex = s.indexOf(searchString);
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
1579 1579
        }
1580 1580
        String result = handler.handleInsertOrUpdateAction(metacatUrl, null, 
1581 1581
                            null, params, username, groupnames);
1582
        System.out.println("$$$$$$$$$$$$ result: " + result);
1583
        if(result.indexOf("<error>") != -1)
1584
        {
1585
            throw new ServiceFailure("1000", "Error inserting or updating document: " + result);
1586
        }
1582 1587
        //String outputS = new String(output.toByteArray());
1583 1588
        logMetacat.debug("CrudService.insertDocument - Metacat returned: " + result);
1584 1589
        logMetacat.debug("Finsished inserting xml document with id " + localId);

Also available in: Unified diff