-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...client/src/main/java/org/apache/servicecomb/demo/springmvc/client/TestDateTimeSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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.servicecomb.demo.springmvc.client; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
|
||
import org.apache.servicecomb.demo.CategorizedTestCase; | ||
import org.apache.servicecomb.demo.TestMgr; | ||
import org.apache.servicecomb.provider.pojo.RpcReference; | ||
import org.springframework.stereotype.Component; | ||
|
||
interface DateTimeSchemaInf { | ||
Date getDate(Date date); | ||
|
||
Date getDatePath(Date date); | ||
|
||
Date postDate(Date date); | ||
|
||
LocalDate getLocalDate(LocalDate date); | ||
|
||
LocalDate getLocalDatePath(LocalDate date); | ||
|
||
LocalDate postLocalDate(LocalDate date); | ||
|
||
LocalDateTime getLocalDateTime(LocalDateTime date); | ||
|
||
LocalDateTime getLocalDateTimePath(LocalDateTime date); | ||
|
||
LocalDateTime postLocalDateTime(LocalDateTime date); | ||
} | ||
|
||
@Component | ||
public class TestDateTimeSchema implements CategorizedTestCase { | ||
@RpcReference(microserviceName = "springmvc", schemaId = "DateTimeSchema") | ||
private DateTimeSchemaInf dateTimeSchemaInf; | ||
|
||
@Override | ||
public void testRestTransport() throws Exception { | ||
testDateTimeSchema(); | ||
} | ||
|
||
@Override | ||
public void testHighwayTransport() throws Exception { | ||
|
||
} | ||
|
||
@Override | ||
public void testAllTransport() throws Exception { | ||
|
||
} | ||
|
||
private void testDateTimeSchema() { | ||
Date date = new Date(); | ||
TestMgr.check(date.getTime(), dateTimeSchemaInf.getDate(date).getTime()); | ||
TestMgr.check(date.getTime(), dateTimeSchemaInf.getDatePath(date).getTime()); | ||
TestMgr.check(date.getTime(), dateTimeSchemaInf.postDate(date).getTime()); | ||
|
||
LocalDate localDate = LocalDate.of(2020, 2, 1); | ||
TestMgr.check(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), | ||
dateTimeSchemaInf.getLocalDate(localDate).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); | ||
TestMgr.check(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), | ||
dateTimeSchemaInf.getLocalDatePath(localDate).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); | ||
TestMgr.check(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), | ||
dateTimeSchemaInf.postLocalDate(localDate).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); | ||
|
||
LocalDateTime localDateTime = LocalDateTime.of(2020, 2, 1, 23, 23, 30, 333); | ||
TestMgr.check(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")), | ||
dateTimeSchemaInf.getLocalDateTime(localDateTime) | ||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"))); | ||
TestMgr.check(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")), | ||
dateTimeSchemaInf.getLocalDateTimePath(localDateTime) | ||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"))); | ||
TestMgr.check(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")), | ||
dateTimeSchemaInf.postLocalDateTime(localDateTime) | ||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"))); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...mvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/DateTimeSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.servicecomb.demo.springmvc.server; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
|
||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@RestSchema(schemaId = "DateTimeSchema") | ||
@RequestMapping(path = "/dateTime", produces = MediaType.APPLICATION_JSON) | ||
public class DateTimeSchema { | ||
@GetMapping(path = "/getDate") | ||
public Date getDate(@RequestParam("date") Date date) { | ||
return date; | ||
} | ||
|
||
@GetMapping(path = "/getDatePath/{date}") | ||
public Date getDatePath(@PathParam("date") Date date) { | ||
return date; | ||
} | ||
|
||
@PostMapping(path = "/postDate") | ||
public Date postDate(@RequestBody Date date) { | ||
return date; | ||
} | ||
|
||
@GetMapping(path = "/getLocalDate") | ||
public LocalDate getLocalDate(@RequestParam("date") LocalDate date) { | ||
return date; | ||
} | ||
|
||
@GetMapping(path = "/getLocalDate/{date}") | ||
public LocalDate getLocalDatePath(@PathParam("date") LocalDate date) { | ||
return date; | ||
} | ||
|
||
@PostMapping(path = "/postLocalDate") | ||
public LocalDate postLocalDate(@RequestBody LocalDate date) { | ||
return date; | ||
} | ||
|
||
@GetMapping(path = "/getLocalDateTime") | ||
public LocalDateTime getLocalDateTime(@RequestParam("date") LocalDateTime date) { | ||
return date; | ||
} | ||
|
||
@GetMapping(path = "/getLocalDateTime/{date}") | ||
public LocalDateTime getLocalDateTimePath(@PathParam("date") LocalDateTime date) { | ||
return date; | ||
} | ||
|
||
@PostMapping(path = "/postLocalDateTime") | ||
public LocalDateTime postLocalDateTime(@RequestBody LocalDateTime date) { | ||
return date; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters