├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── valaxy │ │ └── demo │ │ ├── DemoWorkshopApplication.java │ │ └── controller │ │ └── RepositoryDetailsController.java └── resources │ └── application.properties └── test └── java └── com └── valaxy └── demo ├── AbstractTest.java ├── DemoWorkshopApplicationTests.java └── RepositoryDetailsControllerTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | ./target/* 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ttrend application 2 | 3 | This is a small applicaiton which contains main and test folders. 4 | Main contains application code. 5 | Test contains test cases. 6 | It also contains pom.xml which has all dependences and artfact name and version 7 | 8 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.0.RELEASE 9 | 10 | 11 | com.valaxy 12 | demo-workshop 13 | 2.1.2 14 | demo-workshop 15 | jar 16 | Demo project for Spring Boot 17 | 18 | 19 | 1.8 20 | 3.1.1 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | 35 | org.kohsuke 36 | github-api 37 | 1.99 38 | 39 | 40 | 41 | org.twitter4j 42 | twitter4j-core 43 | 3.0.6 44 | 45 | 46 | 47 | junit 48 | junit 49 | 4.13.1 50 | test 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | org.junit.vintage 60 | junit-vintage-engine 61 | 62 | 63 | junit 64 | junit 65 | 66 | 67 | org.junit.jupiter 68 | org.junit.jupiter.api 69 | 70 | 71 | 72 | 73 | org.mockito 74 | mockito-junit-jupiter 75 | test 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.springframework.boot 84 | spring-boot-maven-plugin 85 | 86 | 87 | org.apache.maven.plugins 88 | maven-surefire-plugin 89 | 2.22.2 90 | 91 | ${argLine} -Xmx2048m 92 | 93 | 94 | 95 | 96 | org.jacoco 97 | jacoco-maven-plugin 98 | 0.8.2 99 | 100 | 101 | 102 | prepare-agent 103 | 104 | 105 | 106 | 107 | report 108 | test 109 | 110 | report 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | dev 121 | file://jarstaging 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/main/java/com/valaxy/demo/DemoWorkshopApplication.java: -------------------------------------------------------------------------------- 1 | package com.stalin.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoWorkshopApplication{ 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoWorkshopApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/valaxy/demo/controller/RepositoryDetailsController.java: -------------------------------------------------------------------------------- 1 | package com.stalin.demo.controller; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.kohsuke.github.GHRepositorySearchBuilder; 8 | import org.kohsuke.github.GitHub; 9 | import org.kohsuke.github.GitHubBuilder; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.core.env.Environment; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import twitter4j.Trend; 18 | import twitter4j.Trends; 19 | import twitter4j.Twitter; 20 | import twitter4j.TwitterException; 21 | import twitter4j.TwitterFactory; 22 | import twitter4j.conf.ConfigurationBuilder; 23 | 24 | @RestController 25 | public class RepositoryDetailsController { 26 | 27 | 28 | 29 | 30 | @Autowired 31 | private Environment env; 32 | 33 | @RequestMapping("/") 34 | public String getRepos() throws IOException { 35 | GitHub github = new GitHubBuilder().withPassword("valaxytech@gmail.com", "XXXXXXXX").build(); 36 | GHRepositorySearchBuilder builder = github.searchRepositories(); 37 | return "Greetings from Valaxy Technologies"; 38 | } 39 | 40 | @GetMapping("/trends") 41 | public Map getTwitterTrends(@RequestParam("placeid") String trendPlace, @RequestParam("count") String trendCount) { 42 | String consumerKey = env.getProperty("CONSUMER_KEY"); 43 | String consumerSecret = env.getProperty("CONSUMER_SECRET"); 44 | String accessToken = env.getProperty("ACCESS_TOKEN"); 45 | String accessTokenSecret = env.getProperty("ACCESS_TOKEN_SECRET"); 46 | System.out.println("consumerKey "+consumerKey+" consumerSecret "+consumerSecret+" accessToken "+accessToken+" accessTokenSecret "+accessTokenSecret); 47 | ConfigurationBuilder cb = new ConfigurationBuilder(); 48 | cb.setDebugEnabled(true) 49 | .setOAuthConsumerKey(consumerKey) 50 | .setOAuthConsumerSecret(consumerSecret) 51 | .setOAuthAccessToken(accessToken) 52 | .setOAuthAccessTokenSecret(accessTokenSecret); 53 | TwitterFactory tf = new TwitterFactory(cb.build()); 54 | System.out.println("Twitter Factory "+tf); 55 | System.out.println("Code testing purpose "); 56 | Twitter twitter = tf.getInstance(); 57 | System.out.println("Twitter object "+twitter); 58 | Map trendDetails = new HashMap(); 59 | try { 60 | Trends trends = twitter.getPlaceTrends(Integer.parseInt(trendPlace)); 61 | System.out.println("After API call"); 62 | int count = 0; 63 | for (Trend trend : trends.getTrends()) { 64 | if (count < Integer.parseInt(trendCount)) { 65 | trendDetails.put(trend.getName(), trend.getURL()); 66 | count++; 67 | } 68 | } 69 | } catch (TwitterException e) { 70 | trendDetails.put("test", "MyTweet"); 71 | //trendDetails.put("Twitter Exception", e.getMessage()); 72 | System.out.println("Twitter exception "+e.getMessage()); 73 | 74 | }catch (Exception e) { 75 | trendDetails.put("test", "MyTweet"); 76 | System.out.println("Exception "+e.getMessage()); 77 | } 78 | return trendDetails; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8000 2 | # Commit for master 1 3 | # Commit for master 2 4 | -------------------------------------------------------------------------------- /src/test/java/com/valaxy/demo/AbstractTest.java: -------------------------------------------------------------------------------- 1 | package com.stalin.demo; 2 | 3 | import com.fasterxml.jackson.core.JsonParseException; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.JsonMappingException; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 14 | import org.springframework.web.context.WebApplicationContext; 15 | 16 | import java.io.IOException; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @SpringBootTest(classes = DemoWorkshopApplication.class) 20 | @WebAppConfiguration 21 | public abstract class AbstractTest { 22 | 23 | protected MockMvc mvc; 24 | @Autowired 25 | WebApplicationContext webApplicationContext; 26 | 27 | protected void setUp() { 28 | mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); 29 | } 30 | protected String mapToJson(Object obj) throws JsonProcessingException { 31 | ObjectMapper objectMapper = new ObjectMapper(); 32 | return objectMapper.writeValueAsString(obj); 33 | } 34 | protected T mapFromJson(String json, Class clazz) 35 | throws JsonParseException, JsonMappingException, IOException { 36 | 37 | ObjectMapper objectMapper = new ObjectMapper(); 38 | return objectMapper.readValue(json, clazz); 39 | } 40 | } -------------------------------------------------------------------------------- /src/test/java/com/valaxy/demo/DemoWorkshopApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.stalin.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import java.util.*; 7 | 8 | @SpringBootTest 9 | class DemoWorkshopApplicationTests { 10 | 11 | @Test 12 | void contextLoads() { 13 | List li = new ArrayList (); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/valaxy/demo/RepositoryDetailsControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.stalin.demo; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.test.web.servlet.MvcResult; 8 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | 12 | 13 | @SpringBootTest 14 | class RepositoryDetailsControllerTest extends AbstractTest { 15 | 16 | @BeforeEach 17 | public void setUp() { 18 | super.setUp(); 19 | } 20 | 21 | 22 | @Test 23 | public void getProductsList() throws Exception { 24 | String uri = "/trends?placeid=1&count=5"; 25 | MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(uri) 26 | .accept(MediaType.APPLICATION_JSON_VALUE)).andReturn(); 27 | int status = mvcResult.getResponse().getStatus(); 28 | assertEquals(200, status); 29 | } 30 | 31 | 32 | 33 | } 34 | --------------------------------------------------------------------------------