[OLINGO-175] open type tests for V4
This commit is contained in:
parent
39d965990e
commit
1585f2da4f
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.fit;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||
import org.apache.olingo.fit.metadata.Metadata;
|
||||
import org.apache.olingo.fit.utils.Accept;
|
||||
import org.apache.olingo.fit.utils.ConstantKey;
|
||||
import org.apache.olingo.fit.utils.Constants;
|
||||
import org.apache.olingo.fit.utils.FSManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Path("/V40/OpenType.svc")
|
||||
public class V4OpenType {
|
||||
|
||||
private final V4Services services;
|
||||
|
||||
private final Metadata openMetadata;
|
||||
|
||||
public V4OpenType() throws Exception {
|
||||
this.openMetadata = new Metadata(FSManager.instance(ODataServiceVersion.V40).
|
||||
readFile("openType" + StringUtils.capitalize(Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)),
|
||||
Accept.XML));
|
||||
this.services = new V4Services() {
|
||||
|
||||
@Override
|
||||
protected Metadata getMetadataObj() {
|
||||
return openMetadata;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Response replaceServiceName(final Response response) {
|
||||
try {
|
||||
final String content = IOUtils.toString((InputStream) response.getEntity(), "UTF-8").
|
||||
replaceAll("Static\\.svc", "OpenType.svc");
|
||||
|
||||
final Response.ResponseBuilder builder = Response.status(response.getStatus());
|
||||
for (String headerName : response.getHeaders().keySet()) {
|
||||
for (Object headerValue : response.getHeaders().get(headerName)) {
|
||||
builder.header(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
final InputStream toBeStreamedBack = IOUtils.toInputStream(content, "UTF-8");
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
IOUtils.copy(toBeStreamedBack, baos);
|
||||
IOUtils.closeQuietly(toBeStreamedBack);
|
||||
|
||||
builder.header("Content-Length", baos.size());
|
||||
builder.entity(new ByteArrayInputStream(baos.toByteArray()));
|
||||
|
||||
return builder.build();
|
||||
} catch (Exception e) {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide sample large metadata.
|
||||
*
|
||||
* @return metadata.
|
||||
*/
|
||||
@GET
|
||||
@Path("/$metadata")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
public Response getMetadata() {
|
||||
return services.getMetadata("openType" + StringUtils.capitalize(
|
||||
Constants.get(ODataServiceVersion.V40, ConstantKey.METADATA)));
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{entitySetName}({entityId})")
|
||||
public Response getEntity(
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
|
||||
@PathParam("entitySetName") String entitySetName,
|
||||
@PathParam("entityId") String entityId,
|
||||
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) String format,
|
||||
@QueryParam("$expand") @DefaultValue(StringUtils.EMPTY) String expand,
|
||||
@QueryParam("$select") @DefaultValue(StringUtils.EMPTY) String select) {
|
||||
|
||||
return replaceServiceName(
|
||||
services.getEntityInternal(accept, entitySetName, entityId, format, expand, select, false));
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{entitySetName}")
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
|
||||
@Consumes({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM})
|
||||
public Response postNewEntity(
|
||||
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) String accept,
|
||||
@HeaderParam("Content-Type") @DefaultValue(StringUtils.EMPTY) String contentType,
|
||||
@HeaderParam("Prefer") @DefaultValue(StringUtils.EMPTY) String prefer,
|
||||
@PathParam("entitySetName") final String entitySetName,
|
||||
final String entity) {
|
||||
|
||||
return replaceServiceName(services.postNewEntity(accept, contentType, prefer, entitySetName, entity));
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{entitySetName}({entityId})")
|
||||
public Response removeEntity(
|
||||
@PathParam("entitySetName") String entitySetName,
|
||||
@PathParam("entityId") String entityId) {
|
||||
|
||||
return replaceServiceName(services.removeEntity(entitySetName, entityId));
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
{
|
||||
"odata.metadata": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/$metadata#Row",
|
||||
"value": [{
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'432f0da9-806e-4a2f-b708-dbd1c57a1c21')",
|
||||
"odata.editLink": "Row(guid'432f0da9-806e-4a2f-b708-dbd1c57a1c21')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "432f0da9-806e-4a2f-b708-dbd1c57a1c21",
|
||||
"Name": "Chris"
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'02d5d465-edb3-4169-9176-89dd7c86535e')",
|
||||
"odata.editLink": "Row(guid'02d5d465-edb3-4169-9176-89dd7c86535e')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "02d5d465-edb3-4169-9176-89dd7c86535e",
|
||||
"Description": "Excellent"
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'8f59bcb4-1bed-4b91-ab74-44628f57f160')",
|
||||
"odata.editLink": "Row(guid'8f59bcb4-1bed-4b91-ab74-44628f57f160')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "8f59bcb4-1bed-4b91-ab74-44628f57f160",
|
||||
"Count": 1
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'5dcbef86-a002-4121-8087-f6160fe9a1ed')",
|
||||
"odata.editLink": "Row(guid'5dcbef86-a002-4121-8087-f6160fe9a1ed')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "5dcbef86-a002-4121-8087-f6160fe9a1ed",
|
||||
"Occurred@odata.type": "Edm.DateTimeOffset",
|
||||
"Occurred": "2001-04-05T05:05:05.001+00:01"
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'71f7d0dc-ede4-45eb-b421-555a2aa1e58f')",
|
||||
"odata.editLink": "Row(guid'71f7d0dc-ede4-45eb-b421-555a2aa1e58f')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "71f7d0dc-ede4-45eb-b421-555a2aa1e58f",
|
||||
"Double": 1.2626
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'672b8250-1e6e-4785-80cf-b94b572e42b3')",
|
||||
"odata.editLink": "Row(guid'672b8250-1e6e-4785-80cf-b94b572e42b3')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "672b8250-1e6e-4785-80cf-b94b572e42b3",
|
||||
"Decimal@odata.type": "Edm.Decimal",
|
||||
"Decimal": "1.26"
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'814d505b-6b6a-45a0-9de0-153b16149d56')",
|
||||
"odata.editLink": "Row(guid'814d505b-6b6a-45a0-9de0-153b16149d56')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "814d505b-6b6a-45a0-9de0-153b16149d56",
|
||||
"Date@odata.type": "Edm.DateTime",
|
||||
"Date": "1999-02-04T00:00:00"
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'2e4904b4-00b0-4e37-9f44-b99a6b208dba')",
|
||||
"odata.editLink": "Row(guid'2e4904b4-00b0-4e37-9f44-b99a6b208dba')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "2e4904b4-00b0-4e37-9f44-b99a6b208dba",
|
||||
"GeomPolygon@odata.type": "Edm.GeometryPolygon",
|
||||
"GeomPolygon": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [],
|
||||
"crs": {
|
||||
"type": "name",
|
||||
"properties": {
|
||||
"name": "EPSG:0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'5a76c54e-4553-4bf6-8592-04cbcbfb1e65')",
|
||||
"odata.editLink": "Row(guid'5a76c54e-4553-4bf6-8592-04cbcbfb1e65')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "5a76c54e-4553-4bf6-8592-04cbcbfb1e65"
|
||||
}, {
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'9f9c963b-5c2f-4e39-8bec-b45d19c5dc85')",
|
||||
"odata.editLink": "Row(guid'9f9c963b-5c2f-4e39-8bec-b45d19c5dc85')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "9f9c963b-5c2f-4e39-8bec-b45d19c5dc85"
|
||||
}]
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
-->
|
||||
<feed xml:base="http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/"
|
||||
xmlns="http://www.w3.org/2005/Atom"
|
||||
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
|
||||
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
|
||||
xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row</id>
|
||||
<title type="text">Row</title>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<link rel="self" title="Row" href="Row"/>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'432f0da9-806e-4a2f-b708-dbd1c57a1c21')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.IndexedRow" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'432f0da9-806e-4a2f-b708-dbd1c57a1c21')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">432f0da9-806e-4a2f-b708-dbd1c57a1c21</d:Id>
|
||||
<d:Name>Chris</d:Name>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'02d5d465-edb3-4169-9176-89dd7c86535e')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.IndexedRow" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'02d5d465-edb3-4169-9176-89dd7c86535e')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">02d5d465-edb3-4169-9176-89dd7c86535e</d:Id>
|
||||
<d:Description>Excellent</d:Description>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'8f59bcb4-1bed-4b91-ab74-44628f57f160')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.IndexedRow" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'8f59bcb4-1bed-4b91-ab74-44628f57f160')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">8f59bcb4-1bed-4b91-ab74-44628f57f160</d:Id>
|
||||
<d:Count m:type="Edm.Int32">1</d:Count>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'5dcbef86-a002-4121-8087-f6160fe9a1ed')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.IndexedRow" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'5dcbef86-a002-4121-8087-f6160fe9a1ed')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">5dcbef86-a002-4121-8087-f6160fe9a1ed</d:Id>
|
||||
<d:Occurred m:type="Edm.DateTimeOffset">2001-04-05T05:05:05.001+00:01</d:Occurred>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'71f7d0dc-ede4-45eb-b421-555a2aa1e58f')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'71f7d0dc-ede4-45eb-b421-555a2aa1e58f')"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">71f7d0dc-ede4-45eb-b421-555a2aa1e58f</d:Id>
|
||||
<d:Double m:type="Edm.Double">1.2626</d:Double>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'672b8250-1e6e-4785-80cf-b94b572e42b3')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'672b8250-1e6e-4785-80cf-b94b572e42b3')"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">672b8250-1e6e-4785-80cf-b94b572e42b3</d:Id>
|
||||
<d:Decimal m:type="Edm.Decimal">1.26</d:Decimal>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'814d505b-6b6a-45a0-9de0-153b16149d56')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'814d505b-6b6a-45a0-9de0-153b16149d56')"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">814d505b-6b6a-45a0-9de0-153b16149d56</d:Id>
|
||||
<d:Date m:type="Edm.DateTime">1999-02-04T00:00:00</d:Date>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'2e4904b4-00b0-4e37-9f44-b99a6b208dba')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'2e4904b4-00b0-4e37-9f44-b99a6b208dba')"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">2e4904b4-00b0-4e37-9f44-b99a6b208dba</d:Id>
|
||||
<d:GeomPolygon m:type="Edm.GeometryPolygon">
|
||||
<gml:Polygon gml:srsName="http://www.opengis.net/def/crs/EPSG/0/0"/>
|
||||
</d:GeomPolygon>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'5a76c54e-4553-4bf6-8592-04cbcbfb1e65')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'5a76c54e-4553-4bf6-8592-04cbcbfb1e65')"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">5a76c54e-4553-4bf6-8592-04cbcbfb1e65</d:Id>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'9f9c963b-5c2f-4e39-8bec-b45d19c5dc85')</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.IndexedRow" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(guid'9f9c963b-5c2f-4e39-8bec-b45d19c5dc85')/Microsoft.Test.OData.Services.OpenTypesService.IndexedRow"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:23:54Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Edm.Guid">9f9c963b-5c2f-4e39-8bec-b45d19c5dc85</d:Id>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
||||
</feed>
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"odata.metadata": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/$metadata#Row/@Element",
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'672b8250-1e6e-4785-80cf-b94b572e42b3')",
|
||||
"odata.editLink": "Row(guid'672b8250-1e6e-4785-80cf-b94b572e42b3')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "672b8250-1e6e-4785-80cf-b94b572e42b3",
|
||||
"Decimal@odata.type": "Edm.Decimal",
|
||||
"Decimal": "1.26"
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
-->
|
||||
<entry xml:base="http://localhost:${cargo.servlet.port}/StaticService/V40/OpenType.svc/"
|
||||
xmlns="http://www.w3.org/2005/Atom"
|
||||
xmlns:d="http://docs.oasis-open.org/odata/ns/data"
|
||||
xmlns:m="http://docs.oasis-open.org/odata/ns/metadata"
|
||||
xmlns:georss="http://www.georss.org/georss"
|
||||
xmlns:gml="http://www.opengis.net/gml"
|
||||
m:context="http://localhost:${cargo.servlet.port}/StaticService/V40/OpenType.svc/$metadata#Row">
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V40/OpenType.svc/Row(672b8250-1e6e-4785-80cf-b94b572e42b3)</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://docs.oasis-open.org/odata/ns/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(672b8250-1e6e-4785-80cf-b94b572e42b3)"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:31:52Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Guid">672b8250-1e6e-4785-80cf-b94b572e42b3</d:Id>
|
||||
<d:Decimal m:type="Decimal">1.26</d:Decimal>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"odata.metadata": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/$metadata#Row/@Element",
|
||||
"odata.type": "Microsoft.Test.OData.Services.OpenTypesService.Row",
|
||||
"odata.id": "http://localhost:${cargo.servlet.port}/StaticService/V30/OpenType.svc/Row(guid'71f7d0dc-ede4-45eb-b421-555a2aa1e58f')",
|
||||
"odata.editLink": "Row(guid'71f7d0dc-ede4-45eb-b421-555a2aa1e58f')",
|
||||
"Id@odata.type": "Edm.Guid",
|
||||
"Id": "71f7d0dc-ede4-45eb-b421-555a2aa1e58f",
|
||||
"Double": 1.2626
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
-->
|
||||
<entry xml:base="http://localhost:${cargo.servlet.port}/StaticService/V40/OpenType.svc/"
|
||||
xmlns="http://www.w3.org/2005/Atom"
|
||||
xmlns:d="http://docs.oasis-open.org/odata/ns/data"
|
||||
xmlns:m="http://docs.oasis-open.org/odata/ns/metadata"
|
||||
xmlns:georss="http://www.georss.org/georss"
|
||||
xmlns:gml="http://www.opengis.net/gml"
|
||||
m:context="http://localhost:${cargo.servlet.port}/StaticService/V40/OpenType.svc/$metadata#Row">
|
||||
<id>http://localhost:${cargo.servlet.port}/StaticService/V40/OpenType.svc/Row(71f7d0dc-ede4-45eb-b421-555a2aa1e58f)</id>
|
||||
<category term="Microsoft.Test.OData.Services.OpenTypesService.Row" scheme="http://docs.oasis-open.org/odata/ns/scheme"/>
|
||||
<link rel="edit" title="Row" href="Row(71f7d0dc-ede4-45eb-b421-555a2aa1e58f)"/>
|
||||
<title/>
|
||||
<updated>2014-04-11T13:30:28Z</updated>
|
||||
<author>
|
||||
<name/>
|
||||
</author>
|
||||
<content type="application/xml">
|
||||
<m:properties>
|
||||
<d:Id m:type="Guid">71f7d0dc-ede4-45eb-b421-555a2aa1e58f</d:Id>
|
||||
<d:Double m:type="Double">1.2626</d:Double>
|
||||
</m:properties>
|
||||
</content>
|
||||
</entry>
|
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
-->
|
||||
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
|
||||
<edmx:DataServices>
|
||||
<Schema Namespace="Microsoft.Test.OData.Services.ODataWCFService" xmlns="http://docs.oasis-open.org/odata/ns/edm">
|
||||
<EnumType Name="Color">
|
||||
<Member Name="Red" Value="1"/>
|
||||
<Member Name="Green" Value="2"/>
|
||||
<Member Name="Blue" Value="4"/>
|
||||
</EnumType>
|
||||
<ComplexType Name="ContactDetails">
|
||||
<Property Name="FirstContacted" Type="Edm.Binary"/>
|
||||
<Property Name="LastContacted" Type="Edm.DateTimeOffset" Nullable="false"/>
|
||||
<Property Name="Contacted" Type="Edm.DateTime" Nullable="false"/>
|
||||
<Property Name="GUID" Type="Edm.Guid" Nullable="false"/>
|
||||
<Property Name="PreferedContactTime" Type="Edm.Time" Nullable="false"/>
|
||||
<Property Name="Byte" Type="Edm.Byte" Nullable="false"/>
|
||||
<Property Name="SignedByte" Type="Edm.SByte" Nullable="false"/>
|
||||
<Property Name="Double" Type="Edm.Double" Nullable="false"/>
|
||||
<Property Name="Single" Type="Edm.Single" Nullable="false"/>
|
||||
<Property Name="Short" Type="Edm.Int16" Nullable="false"/>
|
||||
<Property Name="Int" Type="Edm.Int32" Nullable="false"/>
|
||||
<Property Name="Long" Type="Edm.Int64" Nullable="false"/>
|
||||
</ComplexType>
|
||||
<EntityType Name="Row" OpenType="true">
|
||||
<Key>
|
||||
<PropertyRef Name="Id"/>
|
||||
</Key>
|
||||
<Property Name="Id" Type="Edm.Guid" Nullable="false"/>
|
||||
</EntityType>
|
||||
<EntityType Name="IndexedRow" BaseType="Microsoft.Test.OData.Services.ODataWCFService.Row" OpenType="true"/>
|
||||
<EntityType Name="RowIndex" OpenType="true">
|
||||
<Key>
|
||||
<PropertyRef Name="Id"/>
|
||||
</Key>
|
||||
<Property Name="Id" Type="Edm.Int32" Nullable="false"/>
|
||||
<NavigationProperty Name="Rows" Type="Microsoft.Test.OData.Services.ODataWCFService.Row" Nullable="false"/>
|
||||
</EntityType>
|
||||
<EntityContainer Name="DefaultContainer">
|
||||
<EntitySet Name="Row" EntityType="Microsoft.Test.OData.Services.ODataWCFService.Row">
|
||||
<NavigationPropertyBinding Path="Rows" Target="Row"/>
|
||||
</EntitySet>
|
||||
<EntitySet Name="RowIndex" EntityType="Microsoft.Test.OData.Services.ODataWCFService.RowIndex"/>
|
||||
</EntityContainer>
|
||||
</Schema>
|
||||
</edmx:DataServices>
|
||||
</edmx:Edmx>
|
|
@ -46,6 +46,7 @@
|
|||
<bean class="org.apache.olingo.fit.V4Services"/>
|
||||
<bean class="org.apache.olingo.fit.V4NorthWind"/>
|
||||
<bean class="org.apache.olingo.fit.V4NorthWindExt"/>
|
||||
<bean class="org.apache.olingo.fit.V4OpenType"/>
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/>
|
||||
|
|
|
@ -18,9 +18,17 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.it.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.core.ODataClientFactory;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -33,6 +41,8 @@ public abstract class AbstractTestITCase {
|
|||
|
||||
protected static String testStaticServiceRootURL;
|
||||
|
||||
protected static String testOpenTypeServiceRootURL;
|
||||
|
||||
protected static String testLargeModelServiceRootURL;
|
||||
|
||||
protected static String testAuthServiceRootURL;
|
||||
|
@ -40,6 +50,7 @@ public abstract class AbstractTestITCase {
|
|||
@BeforeClass
|
||||
public static void setUpODataServiceRoot() throws IOException {
|
||||
testStaticServiceRootURL = "http://localhost:9080/StaticService/V40/Static.svc";
|
||||
testOpenTypeServiceRootURL = "http://localhost:9080/StaticService/V40/OpenType.svc";
|
||||
testLargeModelServiceRootURL = "http://localhost:9080/StaticService/V40/Static.svc/large";
|
||||
testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
|
||||
}
|
||||
|
@ -52,4 +63,20 @@ public abstract class AbstractTestITCase {
|
|||
protected ODataClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
|
||||
final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink);
|
||||
req.setFormat(format);
|
||||
|
||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||
final ODataEntity entity = res.getBody();
|
||||
|
||||
assertNotNull(entity);
|
||||
|
||||
if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
|
||||
assertEquals(req.getURI(), entity.getEditLink());
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.client.core.it.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
|
||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
import org.apache.olingo.commons.api.domain.ODataComplexValue;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataProperty;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmSchema;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataPubFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void checkOpenTypeEntityTypesExist() {
|
||||
final Edm metadata = getClient().getRetrieveRequestFactory().
|
||||
getMetadataRequest(testOpenTypeServiceRootURL).execute().getBody();
|
||||
|
||||
final EdmSchema schema = metadata.getSchemas().get(0);
|
||||
|
||||
assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "Row")).isOpenType());
|
||||
assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "IndexedRow")).isOpenType());
|
||||
assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType());
|
||||
}
|
||||
|
||||
private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
|
||||
final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
|
||||
appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid));
|
||||
return read(format, builder.build());
|
||||
}
|
||||
|
||||
private void read(final ODataPubFormat format) {
|
||||
ODataEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f");
|
||||
assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind());
|
||||
|
||||
row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
|
||||
assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readAsAtom() {
|
||||
read(ODataPubFormat.ATOM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readAsJSON() {
|
||||
read(ODataPubFormat.JSON_FULL_METADATA);
|
||||
}
|
||||
|
||||
private void cud(final ODataPubFormat format) {
|
||||
final Integer id = 1426;
|
||||
|
||||
ODataEntity rowIndex = getClient().getObjectFactory().newEntity(
|
||||
new FullQualifiedName("Microsoft.Test.OData.Services.OpenTypesService.RowIndex"));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("Id",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("aString",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("aBoolean",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(true)));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("aDouble",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.5D)));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("aByte",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).
|
||||
build()));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("aDate",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).
|
||||
build()));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newPrimitiveProperty("aDate",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).
|
||||
build()));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newEnumProperty("aColor", getClient().getObjectFactory().
|
||||
newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
|
||||
|
||||
final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
|
||||
"Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.Date).setText("2001-04-05").build()));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.Duration).setText("-P9DT51M10.5063807S").build()));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("SignedByte",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build()));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Double",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(Double.MAX_VALUE)));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Single",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(Float.MAX_VALUE)));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Short",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().
|
||||
setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build()));
|
||||
contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Int",
|
||||
getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(Integer.MAX_VALUE)));
|
||||
getClient().getBinder().add(rowIndex,
|
||||
getClient().getObjectFactory().newComplexProperty("aContact", contactDetails));
|
||||
|
||||
final ODataEntityCreateRequest<ODataEntity> createReq = getClient().getCUDRequestFactory().
|
||||
getEntityCreateRequest(getClient().getURIBuilder(testOpenTypeServiceRootURL).
|
||||
appendEntitySetSegment("RowIndex").build(), rowIndex);
|
||||
createReq.setFormat(format);
|
||||
final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
|
||||
assertEquals(201, createRes.getStatusCode());
|
||||
|
||||
final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
|
||||
appendEntitySetSegment("RowIndex").appendKeySegment(id);
|
||||
rowIndex = read(format, builder.build());
|
||||
assertNotNull(rowIndex);
|
||||
assertEquals(EdmPrimitiveTypeKind.Int32,
|
||||
rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.String,
|
||||
rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind());
|
||||
assertEquals(EdmPrimitiveTypeKind.Boolean,
|
||||
rowIndex.getProperty("aBoolean").getPrimitiveValue().getTypeKind());
|
||||
assertTrue(rowIndex.getProperty("aDouble").hasPrimitiveValue());
|
||||
assertTrue(rowIndex.getProperty("aByte").hasPrimitiveValue());
|
||||
assertTrue(rowIndex.getProperty("aDate").hasPrimitiveValue());
|
||||
assertNotNull(rowIndex.getProperty("aColor"));
|
||||
assertTrue(rowIndex.getProperty("aContact").hasComplexValue());
|
||||
assertTrue(rowIndex.getProperty("aContact").getComplexValue().get("SignedByte").hasPrimitiveValue());
|
||||
|
||||
final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
|
||||
getDeleteRequest(rowIndex.getEditLink()).execute();
|
||||
assertEquals(204, deleteRes.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cudAsAtom() {
|
||||
cud(ODataPubFormat.ATOM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cudAsJSON() {
|
||||
cud(ODataPubFormat.JSON_FULL_METADATA);
|
||||
}
|
||||
|
||||
}
|
|
@ -59,7 +59,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
|||
}
|
||||
|
||||
final String timeZoneOffset = matcher.group(9) != null && matcher.group(10) != null
|
||||
&& !matcher.group(10).matches("[-+]0+:0+") ? matcher.group(10) : null;
|
||||
&& !matcher.group(10).matches("[-+]0+:0+") ? matcher.group(10) : null;
|
||||
final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset));
|
||||
if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
|
@ -90,8 +90,8 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
|||
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
|
||||
}
|
||||
final String milliSeconds = decimals.length() > 3
|
||||
? decimals.substring(0, 3)
|
||||
: decimals + "000".substring(decimals.length());
|
||||
? decimals.substring(0, 3)
|
||||
: decimals + "000".substring(decimals.length());
|
||||
dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
|
||||
|
||||
if (!decimals.isEmpty()) {
|
||||
|
@ -143,6 +143,13 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
|||
return returnType.cast(dateTimeValue.getTimeInMillis()); // may throw IllegalArgumentException
|
||||
} else if (returnType.isAssignableFrom(Date.class)) {
|
||||
return returnType.cast(dateTimeValue.getTime()); // may throw IllegalArgumentException
|
||||
} else if (returnType.isAssignableFrom(Timestamp.class)) {
|
||||
final Timestamp timestamp = new Timestamp(dateTimeValue.getTimeInMillis()); // may throw IllegalArgumentException
|
||||
if (dateTimeValue.get(Calendar.MILLISECOND) > 0) {
|
||||
timestamp.setNanos(dateTimeValue.get(Calendar.MILLISECOND)); // may throw IllegalArgumentException
|
||||
}
|
||||
|
||||
return returnType.cast(timestamp);
|
||||
} else {
|
||||
throw new ClassCastException("unsupported return type " + returnType.getSimpleName());
|
||||
}
|
||||
|
@ -192,7 +199,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
|||
}
|
||||
|
||||
final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET)
|
||||
+ dateTimeValue.get(Calendar.DST_OFFSET)) / 60 / 1000;
|
||||
+ dateTimeValue.get(Calendar.DST_OFFSET)) / 60 / 1000;
|
||||
final int offsetHours = offsetInMinutes / 60;
|
||||
final int offsetMinutes = Math.abs(offsetInMinutes % 60);
|
||||
final String offsetString = offsetInMinutes == 0 ? "Z" : String.format("%+03d:%02d", offsetHours, offsetMinutes);
|
||||
|
|
Loading…
Reference in New Issue