Project

General

Profile

« Previous | Next » 

Revision 5869

Added by berkley almost 14 years ago

fixed compile errors

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
41 41
import junit.framework.TestSuite;
42 42

  
43 43
import org.apache.commons.io.IOUtils;
44
import org.apache.log.LogEvent;
45 44
import org.dataone.service.exceptions.InvalidRequest;
46 45
import org.dataone.service.exceptions.InvalidToken;
47 46
import org.dataone.service.exceptions.NotAuthorized;
test/edu/ucsb/nceas/metacat/util/MetacatPopulatorTest.java
39 39
import junit.framework.Test;
40 40
import junit.framework.TestSuite;
41 41

  
42
import org.apache.log.LogEvent;
43 42
import org.dataone.service.exceptions.InvalidRequest;
44 43
import org.dataone.service.exceptions.InvalidToken;
45 44
import org.dataone.service.exceptions.NotAuthorized;
test/edu/ucsb/nceas/metacat/restservice/ResourceHandlerTest.java
30 30

  
31 31
import edu.ucsb.nceas.MCTestCase;
32 32
import edu.ucsb.nceas.metacat.dataone.CrudServiceTest;
33
import edu.ucsb.nceas.metacat.properties.PropertyService;
33 34

  
34 35
import junit.framework.Test;
35 36
import junit.framework.TestSuite;
36 37

  
37 38
import org.apache.commons.io.IOUtils;
39
import org.dataone.service.exceptions.BaseException;
40
import org.dataone.service.exceptions.InvalidSystemMetadata;
41
import org.dataone.service.exceptions.ServiceFailure;
42
import org.dataone.service.types.SystemMetadata;
38 43

  
44
import org.jibx.runtime.BindingDirectory;
45
import org.jibx.runtime.IBindingFactory;
46
import org.jibx.runtime.IMarshallingContext;
47
import org.jibx.runtime.IUnmarshallingContext;
48
import org.jibx.runtime.JiBXException;
49

  
39 50
/**
40 51
 * @author berkley
41 52
 * class to test ResourceHandler
......
55 66
        TestSuite suite = new TestSuite();
56 67
        
57 68
        //suite.addTest(new ResourceHandlerTest("testFindBoundary"));        
58
        suite.addTest(new ResourceHandlerTest("testProcessMMP"));
59

  
69
        //suite.addTest(new ResourceHandlerTest("testProcessMMP"));
70
        suite.addTest(new ResourceHandlerTest("testReplicate"));
60 71
        return suite;
61 72
    }
62 73
    
74
    public void testReplicate()
75
    {
76
        
77
    }
78
    
63 79
    public void testFindBoundary()
64 80
    {
65 81
        try
......
93 109
        
94 110
    }
95 111
    
112
    /**
113
     * create a mime multipart message from object and sysmeta and write it to out
114
     */
115
    private void createMimeMultipart(OutputStream out, InputStream object,
116
            SystemMetadata sysmeta) throws IOException, BaseException
117
    {
118
        if (sysmeta == null) {
119
            throw new InvalidSystemMetadata("1000",
120
                    "System metadata was null.  Can't create multipart form.");
121
        }
122
        Date d = new Date();
123
        String boundary = d.getTime() + "";
124

  
125
        String mime = "MIME-Version:1.0\n";
126
        mime += "Content-type:multipart/mixed; boundary=\"" + boundary + "\"\n";
127
        boundary = "--" + boundary + "\n";
128
        mime += boundary;
129
        mime += "Content-Disposition: attachment; filename=systemmetadata\n\n";
130
        out.write(mime.getBytes());
131
        out.flush();
132
        
133
        //write the sys meta
134
        try
135
        {
136
            ByteArrayInputStream bais = serializeSystemMetadata(sysmeta);
137
            IOUtils.copy(bais, out);
138
        }
139
        catch(Exception e)
140
        {
141
            throw new ServiceFailure("1000",
142
                    "Could not serialize the system metadata to multipart: "
143
                            + e.getMessage());
144
        }
145
        
146
        out.write("\n".getBytes()); 
147

  
148
        if (object != null) 
149
        {    
150
            out.write(boundary.getBytes());
151
            out.write("Content-Disposition: attachment; filename=object\n\n".getBytes());
152
            try {
153
                mime += IOUtils.copy(object, out);
154
            } 
155
            catch (IOException ioe) 
156
            {
157
                throw new ServiceFailure("1000",
158
                        "Error serializing object to multipart: "
159
                                + ioe.getMessage());
160
            }
161
            out.write("\n".getBytes());
162
        }
163

  
164
        out.write((boundary + "--").getBytes());        
165
    }
166
    
167
    protected ByteArrayInputStream serializeSystemMetadata(SystemMetadata sysmeta)
168
        throws Exception 
169
    {
170

  
171
        ByteArrayOutputStream sysmetaOut = new ByteArrayOutputStream();
172
        serializeServiceType(SystemMetadata.class, sysmeta, sysmetaOut);
173
        ByteArrayInputStream sysmetaStream = new ByteArrayInputStream(
174
                sysmetaOut.toByteArray());
175
        return sysmetaStream;
176
    }
177
    
178
    protected void serializeServiceType(Class type, Object object,
179
            OutputStream out) throws Exception {
180
        IBindingFactory bfact = BindingDirectory.getFactory(type);
181
        IMarshallingContext mctx = bfact.createMarshallingContext();
182
        mctx.marshalDocument(object, "UTF-8", null, out);
183
    }
184
    
96 185
    private void runTestProccessMMP(String filename, String answerFilename)
97 186
        throws Exception
98 187
    {
188
        /*PropertyService propServ = PropertyService.getInstance("/Users/berkley/tools/tomcat/webapps/knb/WEB-INF");
99 189
        System.out.println("*****************************************");
100 190
        System.out.println("running process test on file " + filename);
101 191
        File f = new File(filename);
......
113 203
        String fObjectStr = IOUtils.toString(fobjectis);
114 204
        assertTrue(fObjectStr.trim().equals(obj.trim()));
115 205
        assertTrue(sm.indexOf("<d1:systemMetadata") != -1);
116
        assertTrue(sm.indexOf("</d1:systemMetadata>") != -1);
206
        assertTrue(sm.indexOf("</d1:systemMetadata>") != -1);*/
117 207
    }
118 208
}

Also available in: Unified diff