Example usage for org.springframework.http MediaType MediaType

List of usage examples for org.springframework.http MediaType MediaType

Introduction

In this page you can find the example usage for org.springframework.http MediaType MediaType.

Prototype

public MediaType(MediaType other, @Nullable Map<String, String> parameters) 

Source Link

Document

Copy-constructor that copies the type and subtype of the given MediaType , and allows for different parameters.

Usage

From source file:de.qucosa.webapi.v1.DocumentResourceFileTest.java

@Test
public void changingPathNameRenamesFileOnDiskAndChangesDatastreamUri() throws Exception {
    mockMvc.perform(put("/document/4711").accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>" + "<File id=\"1\">"
                    + "   <PathName>1057131155078-6506.pdf</PathName>" + "   <SortOrder>0</SortOrder>"
                    + "   <Label>Volltextdokument (PDF)</Label>" + "   <FileType/>"
                    + "   <MimeType>application/pdf</MimeType><Language/>" + "   <TempFile/>"
                    + "   <FileSize>1401415</FileSize>" + "   <HashValue>"
                    + "       <Type>md5</Type><Value>cb961ca0c79086341cdc454ea627d975</Value>"
                    + "   </HashValue>" + "   <HashValue>"
                    + "       <Type>sha512</Type><Value>de27573ce9f8ca6f9183609f862796a7aea2e1fdb5741898116ca07ea8d4e537525b853dd2941dcb331b8d09c275acaec643ee976c4ce69c91bfff70d5c1898a</Value>\n"
                    + "   </HashValue>" + "   <OaiExport>1</OaiExport>"
                    + "   <FrontdoorVisible>1</FrontdoorVisible>" + "</File>" + "<File id=\"2\">"
                    + "   <PathName>new-name.pdf</PathName>" + // former "another.pdf"
                    "   <MimeType>application/pdf</MimeType><Language/>" + "   <FileSize>1401415</FileSize>"
                    + "   <OaiExport>1</OaiExport>" + "   <FrontdoorVisible>1</FrontdoorVisible>" + "</File>"
                    + "</Opus_Document>" + "</Opus>"))
            .andExpect(status().isOk());

    ArgumentCaptor<URI> argCapt = ArgumentCaptor.forClass(URI.class);
    verify(fedoraRepository).updateExternalReferenceDatastream(eq("qucosa:4711"), eq("QUCOSA-ATT-2"),
            anyString(), argCapt.capture(), anyString());
    assertTrue(argCapt.getValue().toASCIIString().contains("new-name.pdf"));

    assertFileNotExists("4711/another.pdf", dataFolder.getRoot());
    assertFileExists("4711/new-name.pdf", dataFolder.getRoot());
}

From source file:de.qucosa.webapi.v1.DocumentResourceTest.java

@Test
public void deletingURNGeneratesNewOneInQucosaXML() throws Exception {
    when(fedoraRepository.hasObject("qucosa:4711")).thenReturn(true);
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "QUCOSA-XML")).thenReturn(IOUtils.toInputStream(
            "<Opus version=\"2.0\">" + "<Opus_Document>" + "<TitleMain><Value>Macbeth</Value></TitleMain>"
                    + "<IdentifierUrn><Value>urn:nbn:foo-47118</Value></IdentifierUrn>" + "</Opus_Document>"
                    + "</Opus>"));
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "DC")).thenReturn(
            IOUtils.toInputStream("<oai:dc xmlns:oai=\"http://www.openarchives.org/OAI/2.0/oai_dc/\">"
                    + "<ns:title xmlns:ns=\"http://purl.org/dc/elements/1.1/\">Macbeth</ns:title>"
                    + "<ns:identifier xmlns:ns=\"http://purl.org/dc/elements/1.1/\">urn:nbn:foo-47118"
                    + "</ns:identifier>" + "</oai:dc>"));

    mockMvc.perform(//from w  ww .  ja va2 s.c  o  m
            put(DOCUMENT_PUT_URL_WITHOUT_PARAMS).accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
                    .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
                    .content("<Opus version=\"2.0\">" + "<Opus_Document>" + "<IdentifierUrn/>"
                            + "</Opus_Document>" + "</Opus>"))
            .andExpect(status().isOk());

    ArgumentCaptor<InputStream> argCapt = ArgumentCaptor.forClass(InputStream.class);
    verify(fedoraRepository).modifyDatastreamContent(eq("qucosa:4711"), eq("QUCOSA-XML"),
            eq("application/vnd.slub.qucosa-v1+xml"), argCapt.capture());
    Document control = XMLUnit.buildControlDocument(new InputSource(argCapt.getValue()));
    assertXpathEvaluatesTo(DEFAULT_URN_PREFIX + "-47118", "/Opus/Opus_Document/IdentifierUrn/Value", control);
}

From source file:de.qucosa.webapi.v1.DocumentResourceFileTest.java

@Test
public void dontTouchDatastreamsIfNoFileElementInUpdateXML() throws Exception {
    mockMvc.perform(put("/document/4711").accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>" + "</Opus_Document>" + "</Opus>"))
            .andExpect(status().isOk());

    verify(fedoraRepository, never()).updateExternalReferenceDatastream(anyString(), anyString(), anyString(),
            any(URI.class), anyString());
}

From source file:de.qucosa.webapi.v1.DocumentResourceTest.java

@Test
public void addsNewIdentifierToDigitalObjectDublinCoreDatastream() throws Exception {
    when(fedoraRepository.hasObject("qucosa:4711")).thenReturn(true);
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "QUCOSA-XML")).thenReturn(IOUtils.toInputStream(
            "<Opus version=\"2.0\">" + "<Opus_Document>" + "<TitleMain><Value>Macbeth</Value></TitleMain>"
                    + "<IdentifierUrn><Value>urn:nbn:foo-4711</Value></IdentifierUrn>" + "</Opus_Document>"
                    + "</Opus>"));
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "DC")).thenReturn(
            IOUtils.toInputStream("<oai:dc xmlns:oai=\"http://www.openarchives.org/OAI/2.0/oai_dc/\">"
                    + "<ns:title xmlns:ns=\"http://purl.org/dc/elements/1.1/\">Macbeth</ns:title>"
                    + "<ns:identifier xmlns:ns=\"http://purl.org/dc/elements/1.1/\">urn:nbn:de:slub-dresden:qucosa:47116"
                    + "</ns:identifier>" + "</oai:dc>"));

    mockMvc.perform(put(DOCUMENT_PUT_URL).accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>" + "<IdentifierUrn/>" + "</Opus_Document>"
                    + "</Opus>"))
            .andExpect(status().isOk());

    ArgumentCaptor<InputStream> argCapt = ArgumentCaptor.forClass(InputStream.class);
    verify(fedoraRepository, atLeastOnce()).modifyDatastreamContent(eq("qucosa:4711"), eq("DC"), eq("text/xml"),
            argCapt.capture());/*from   w ww. j  av a2  s .  c  om*/
    Document control = XMLUnit.buildControlDocument(new InputSource(argCapt.getValue()));
    assertXpathExists("//oai:dc/ns:identifier[text()='urn:nbn:de:slub-dresden:qucosa:47116']", control);
    assertXpathExists("//oai:dc/ns:identifier[text()='" + DEFAULT_URN_PREFIX + "-47118']", control);
}

From source file:de.qucosa.webapi.v1.DocumentResourceFileTest.java

@Test
public void addsHashValueElement() throws Exception {
    tempFolder.newFile("tmp-4711.pdf");
    final String SHA512 = "e3aeef00891378c0750606f0328f9fb385e900a2bc8faf015fdf87c1f37acfab3a3768bab20c0eaeb5e25ae985683e0d4a5da480bfc4f83ee02f4a073b3b84c6";

    DatastreamProfile dsp = mock(DatastreamProfile.class);
    when(dsp.getDsChecksumType()).thenReturn("SHA-512");
    when(dsp.getDsChecksum()).thenReturn(SHA512);
    when(fedoraRepository.createExternalReferenceDatastream(eq("qucosa:815"), eq("QUCOSA-ATT-1"),
            eq("Volltextdokument (PDF)"), any(URI.class), anyString(), eq("A"))).thenReturn(dsp);

    mockMvc.perform(post("/document").accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>" + "   <DocumentId>815</DocumentId>"
                    + "       <PersonAuthor>" + "           <LastName>Shakespear</LastName>"
                    + "           <FirstName>William</FirstName>" + "       </PersonAuthor>" + "   <TitleMain>"
                    + "       <Value>Macbeth</Value>" + "   </TitleMain>" + "   <IdentifierUrn>"
                    + "       <Value>urn:nbn:foo-4711</Value>" + "   </IdentifierUrn>" + "   <File>"
                    + "       <PathName>1057131155078-6506.pdf</PathName>"
                    + "       <Label>Volltextdokument (PDF)</Label>"
                    + "       <TempFile>tmp-4711.pdf</TempFile>" + "       <OaiExport>1</OaiExport>"
                    + "       <FrontdoorVisible>1</FrontdoorVisible>" + "   </File>" + "</Opus_Document>"
                    + "</Opus>"))
            .andExpect(status().isCreated());

    ArgumentCaptor<InputStream> argCapt = ArgumentCaptor.forClass(InputStream.class);
    verify(fedoraRepository).modifyDatastreamContent(eq("qucosa:815"), eq("QUCOSA-XML"), anyString(),
            argCapt.capture());// ww w.j a  v a  2 s. co  m
    Document control = XMLUnit.buildControlDocument(new InputSource(argCapt.getValue()));

    assertXpathExists("/Opus/Opus_Document/File/HashValue[Type='SHA-512']", control);
    assertXpathExists("/Opus/Opus_Document/File/HashValue[Value='" + SHA512 + "']", control);
}

From source file:com.catalog.core.Api.java

private HttpEntity<?> getAuthHttpEntity() {
    LoginCredentials loginCred = getLoginCredentials();
    if (loginCred == null)
        return null;

    HttpAuthentication authHeader = new HttpBasicAuthentication(loginCred.getUsername(),
            loginCred.getPassword());//from   www. j a v  a  2s  . co m
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setContentType(new MediaType("application", "json"));

    requestHeaders.setContentType(MediaType.APPLICATION_JSON);
    requestHeaders.setAuthorization(authHeader);
    HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

    return requestEntity;
}

From source file:de.qucosa.webapi.v1.DocumentResourceTest.java

@Test
public void updatedDublinCoreTitle() throws Exception {
    when(fedoraRepository.hasObject("qucosa:4711")).thenReturn(true);
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "QUCOSA-XML")).thenReturn(IOUtils.toInputStream(
            "<Opus version=\"2.0\">" + "<Opus_Document>" + "<TitleMain><Value>Mc Donalds</Value></TitleMain>"
                    + "<IdentifierUrn><Value>urn:nbn:foo-4711</Value></IdentifierUrn>" + "</Opus_Document>"
                    + "</Opus>"));
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "DC")).thenReturn(
            IOUtils.toInputStream("<oai:dc xmlns:oai=\"http://www.openarchives.org/OAI/2.0/oai_dc/\">"
                    + "<ns:title xmlns:ns=\"http://purl.org/dc/elements/1.1/\">Mc Donalds</ns:title>"
                    + "<ns:identifier xmlns:ns=\"http://purl.org/dc/elements/1.1/\">urn:nbn:de:slub-dresden:qucosa:47116"
                    + "</ns:identifier>" + "</oai:dc>"));

    mockMvc.perform(put(DOCUMENT_PUT_URL).accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>"
                    + "<TitleMain><Value>Macbeth</Value></TitleMain>" + "</Opus_Document>" + "</Opus>"))
            .andExpect(status().isOk());

    ArgumentCaptor<InputStream> argCapt = ArgumentCaptor.forClass(InputStream.class);
    verify(fedoraRepository, atLeastOnce()).modifyDatastreamContent(eq("qucosa:4711"), eq("DC"), eq("text/xml"),
            argCapt.capture());// w  ww .ja  va2s . com
    Document control = XMLUnit.buildControlDocument(new InputSource(argCapt.getValue()));
    assertXpathExists("//oai:dc/ns:title[text()='Macbeth']", control);
}

From source file:org.openscience.cdk.app.DepictController.java

private HttpEntity<byte[]> makeResponse(byte[] bytes, String contentType) {
    HttpHeaders header = new HttpHeaders();
    String type = contentType.substring(0, contentType.indexOf('/'));
    String subtype = contentType.substring(contentType.indexOf('/') + 1, contentType.length());
    header.setContentType(new MediaType(type, subtype));
    header.add("Access-Control-Allow-Origin", "*");
    header.set(HttpHeaders.CACHE_CONTROL, "max-age=31536000");
    header.setContentLength(bytes.length);
    return new HttpEntity<>(bytes, header);
}

From source file:de.qucosa.webapi.v1.DocumentResourceFileTest.java

@Test
public void addsMimeTypeElement() throws Exception {
    Path src = new File(this.getClass().getResource("/blank.pdf").toURI()).toPath();
    Path dest = tempFolder.getRoot().toPath().resolve(src.getFileName());
    Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING);

    mockMvc.perform(post("/document").accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>" + "   <DocumentId>815</DocumentId>"
                    + "       <PersonAuthor>" + "           <LastName>Shakespear</LastName>"
                    + "           <FirstName>William</FirstName>" + "       </PersonAuthor>" + "   <TitleMain>"
                    + "       <Value>Macbeth</Value>" + "   </TitleMain>" + "   <IdentifierUrn>"
                    + "       <Value>urn:nbn:foo-4711</Value>" + "   </IdentifierUrn>" + "   <File>"
                    + "       <PathName>1057131155078-6506.pdf</PathName>"
                    + "       <Label>Volltextdokument (PDF)</Label>" + "       <TempFile>blank.pdf</TempFile>"
                    + "       <OaiExport>1</OaiExport>" + "       <FrontdoorVisible>1</FrontdoorVisible>"
                    + "   </File>" + "</Opus_Document>" + "</Opus>"))
            .andExpect(status().isCreated());

    ArgumentCaptor<InputStream> argCapt = ArgumentCaptor.forClass(InputStream.class);
    verify(fedoraRepository).modifyDatastreamContent(eq("qucosa:815"), eq("QUCOSA-XML"), anyString(),
            argCapt.capture());/*from  w w w.  j av a 2  s  .c  o m*/
    Document control = XMLUnit.buildControlDocument(new InputSource(argCapt.getValue()));

    assertXpathExists("/Opus/Opus_Document/File[MimeType='application/pdf']", control);
}

From source file:de.qucosa.webapi.v1.DocumentResourceTest.java

@Test
public void addsNewIdentifierToDCDatastreamOnlyOnce() throws Exception {
    when(fedoraRepository.hasObject("qucosa:4711")).thenReturn(true);
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "QUCOSA-XML")).thenReturn(IOUtils.toInputStream(
            "<Opus version=\"2.0\">" + "<Opus_Document>" + "<TitleMain><Value>Macbeth</Value></TitleMain>"
                    + "<IdentifierUrn><Value>urn:nbn:de:slub-dresden:qucosa:47116</Value></IdentifierUrn>"
                    + "</Opus_Document>" + "</Opus>"));
    when(fedoraRepository.getDatastreamContent("qucosa:4711", "DC")).thenReturn(
            IOUtils.toInputStream("<oai:dc xmlns:oai=\"http://www.openarchives.org/OAI/2.0/oai_dc/\">"
                    + "<ns:title xmlns:ns=\"http://purl.org/dc/elements/1.1/\">Macbeth</ns:title>"
                    + "<ns:identifier xmlns:ns=\"http://purl.org/dc/elements/1.1/\">urn:nbn:de:slub-dresden:qucosa:47116"
                    + "</ns:identifier>" + "</oai:dc>"));

    mockMvc.perform(put(DOCUMENT_PUT_URL_WITHOUT_PARAMS)
            .accept(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .contentType(new MediaType("application", "vnd.slub.qucosa-v1+xml"))
            .content("<Opus version=\"2.0\">" + "<Opus_Document>"
                    + "<IdentifierUrn><Value>urn:nbn:de:slub-dresden:qucosa:47116</Value></IdentifierUrn>"
                    + "</Opus_Document>" + "</Opus>"))
            .andExpect(status().isOk());

    ArgumentCaptor<InputStream> argCapt = ArgumentCaptor.forClass(InputStream.class);
    verify(fedoraRepository, atLeastOnce()).modifyDatastreamContent(eq("qucosa:4711"), eq("DC"), eq("text/xml"),
            argCapt.capture());//from   w w  w . j  a v  a 2 s .  co  m
    Document control = XMLUnit.buildControlDocument(new InputSource(argCapt.getValue()));
    assertXpathNotExists("//oai:dc/ns:identifier[2]", control);
}