This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
forked from phoenixnap/springmvc-raml-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Aleksandar Stojsavljevic
committed
May 30, 2017
1 parent
9f9dcc6
commit 5cfdc47
Showing
6 changed files
with
305 additions
and
26 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
40 changes: 40 additions & 0 deletions
40
...rser/src/test/java/com/phoenixnap/oss/ramlapisync/generation/rules/Issue159RulesTest.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,40 @@ | ||
package com.phoenixnap.oss.ramlapisync.generation.rules; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import com.phoenixnap.oss.ramlapisync.data.ApiResourceMetadata; | ||
import com.phoenixnap.oss.ramlapisync.generation.RamlParser; | ||
import com.phoenixnap.oss.ramlapisync.pojo.PojoGenerationConfig; | ||
import com.phoenixnap.oss.ramlapisync.raml.InvalidRamlResourceException; | ||
import com.sun.codemodel.JCodeModel; | ||
import com.sun.codemodel.JDefinedClass; | ||
|
||
/** | ||
* @author aleksandars | ||
* @since 0.10.5 | ||
*/ | ||
public class Issue159RulesTest extends AbstractRuleTestBase { | ||
|
||
private Rule<JCodeModel, JDefinedClass, ApiResourceMetadata> rule; | ||
|
||
public Issue159RulesTest() { | ||
super(); | ||
defaultRamlParser = new RamlParser(new PojoGenerationConfig().withPackage("com.gen.test", null), "/api", false, | ||
false, 2); | ||
} | ||
|
||
@BeforeClass | ||
public static void initRaml() throws InvalidRamlResourceException { | ||
AbstractRuleTestBase.RAML = RamlLoader.loadRamlFromFile(AbstractRuleTestBase.RESOURCE_BASE + "issue-159.raml"); | ||
} | ||
|
||
@Test | ||
public void applySpring4ClientStubRule_shouldCreate_validCode() throws Exception { | ||
|
||
rule = new Spring4RestTemplateClientRule(); | ||
rule.apply(getControllerMetadata(), jCodeModel); | ||
String removedSerialVersionUID = removeSerialVersionUID(serializeModel()); | ||
verifyGeneratedCode("Issue159Spring4ControllerStub", removedSerialVersionUID); | ||
} | ||
} |
220 changes: 220 additions & 0 deletions
220
springmvc-raml-parser/src/test/resources/rules/Issue159Spring4ControllerStub.java.txt
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,220 @@ | ||
-----------------------------------com.gen.test.model.Manager.java----------------------------------- | ||
|
||
package com.gen.test.model; | ||
|
||
import java.io.Serializable; | ||
import org.apache.commons.lang.builder.EqualsBuilder; | ||
import org.apache.commons.lang.builder.HashCodeBuilder; | ||
import org.apache.commons.lang.builder.ToStringBuilder; | ||
|
||
public class Manager implements Serializable | ||
{ | ||
|
||
private String firstName; | ||
private String lastName; | ||
private String departman; | ||
|
||
/** | ||
* Creates a new Manager. | ||
* | ||
*/ | ||
public Manager() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Creates a new Manager. | ||
* | ||
*/ | ||
public Manager(String firstName, String lastName, String departman) { | ||
super(); | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.departman = departman; | ||
} | ||
|
||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this); | ||
} | ||
|
||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
if ((other instanceof Manager) == false) { | ||
return false; | ||
} | ||
Manager otherObject = ((Manager) other); | ||
return new EqualsBuilder().isEquals(); | ||
} | ||
|
||
public int hashCode() { | ||
return new HashCodeBuilder().toHashCode(); | ||
} | ||
|
||
/** | ||
* Returns the firstName. | ||
* | ||
* @return | ||
* firstName | ||
*/ | ||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
/** | ||
* Set the firstName. | ||
* | ||
* @param firstName | ||
* the new firstName | ||
*/ | ||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
/** | ||
* Returns the lastName. | ||
* | ||
* @return | ||
* lastName | ||
*/ | ||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
/** | ||
* Set the lastName. | ||
* | ||
* @param lastName | ||
* the new lastName | ||
*/ | ||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
/** | ||
* Returns the departman. | ||
* | ||
* @return | ||
* departman | ||
*/ | ||
public String getDepartman() { | ||
return departman; | ||
} | ||
|
||
/** | ||
* Set the departman. | ||
* | ||
* @param departman | ||
* the new departman | ||
*/ | ||
public void setDepartman(String departman) { | ||
this.departman = departman; | ||
} | ||
|
||
} | ||
-----------------------------------com.gen.test.PersonManagerClient.java----------------------------------- | ||
|
||
package com.gen.test; | ||
|
||
import java.util.List; | ||
import com.gen.test.model.Manager; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
|
||
/** | ||
* No description | ||
* (Generated with springmvc-raml-parser v.${project.version}) | ||
* | ||
*/ | ||
public interface PersonManagerClient { | ||
|
||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<List<Manager>> getPersonsManagers(); | ||
|
||
/** | ||
* No description | ||
* | ||
* @param manager The Request Body Payload | ||
*/ | ||
public ResponseEntity<Manager> createPersonsManager(Manager manager); | ||
|
||
} | ||
-----------------------------------com.gen.test.PersonManagerClientImpl.java----------------------------------- | ||
|
||
package com.gen.test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import com.gen.test.model.Manager; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponents; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
|
||
/** | ||
* No description | ||
* (Generated with springmvc-raml-parser v.${project.version}) | ||
* | ||
*/ | ||
@Component | ||
public class PersonManagerClientImpl | ||
implements PersonManagerClient | ||
{ | ||
|
||
@Autowired | ||
private RestTemplate restTemplate; | ||
@Value("${client.url}") | ||
private String baseUrl; | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<List<Manager>> getPersonsManagers() { | ||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
// Add Accepts Headers and Body Content-Type | ||
ArrayList<MediaType> acceptsList = new ArrayList<MediaType>(); | ||
acceptsList.add(MediaType.valueOf("application/json")); | ||
httpHeaders.setAccept(acceptsList); | ||
String url = baseUrl.concat("/organization/persons/managers"); | ||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url); | ||
UriComponents uriComponents = builder.build(); | ||
HttpEntity httpEntity = new HttpEntity(httpHeaders); | ||
class _P extends org.springframework.core.ParameterizedTypeReference<java.util.List<com.gen.test.model.Manager>>{}; | ||
ParameterizedTypeReference<List<Manager>> typeReference = new _P(); | ||
return this.restTemplate.exchange(uriComponents.encode().toUri(), HttpMethod.GET, httpEntity, typeReference); | ||
} | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<Manager> createPersonsManager(Manager manager) { | ||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
// Add Accepts Headers and Body Content-Type | ||
ArrayList<MediaType> acceptsList = new ArrayList<MediaType>(); | ||
httpHeaders.setContentType(MediaType.valueOf("application/json")); | ||
acceptsList.add(MediaType.valueOf("application/json")); | ||
httpHeaders.setAccept(acceptsList); | ||
String url = baseUrl.concat("/organization/persons/managers"); | ||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url); | ||
UriComponents uriComponents = builder.build(); | ||
HttpEntity httpEntity = new HttpEntity(manager, httpHeaders); | ||
return this.restTemplate.exchange(uriComponents.encode().toUri(), HttpMethod.POST, httpEntity, Manager.class); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
springmvc-raml-parser/src/test/resources/rules/issue-159.raml
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,25 @@ | ||
#%RAML 1.0 | ||
title: Managers | ||
mediaType: application/json | ||
baseUri: /api | ||
types: | ||
Manager: | ||
properties: | ||
firstName: string | ||
lastName: string | ||
departman: string | ||
|
||
/organization: | ||
/persons: | ||
/managers: | ||
get: | ||
responses: | ||
200: | ||
body: Manager[] | ||
post: | ||
body: Manager | ||
responses: | ||
201: | ||
body: | ||
application/json: | ||
type: Manager |