Skip to content

Commit 00dc664

Browse files
committed
Refactoring to use get token
1 parent 3aeb026 commit 00dc664

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

complete/src/main/java/hello/Application.java renamed to complete/src/main/java/gettoken/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package hello;
1+
package gettoken;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;

complete/src/main/java/hello/GreetingController.java renamed to complete/src/main/java/gettoken/GetTokenController.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
package hello;
1+
package gettoken;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.databind.node.ObjectNode;
55
import org.springframework.beans.factory.annotation.Value;
6-
import org.springframework.boot.SpringApplication;
7-
import org.springframework.core.env.Environment;
86
import org.springframework.web.bind.annotation.*;
97

108
import java.io.BufferedReader;
@@ -15,25 +13,22 @@
1513

1614

1715
@RestController
18-
public class GreetingController {
16+
public class GetTokenController {
1917

2018
@Value("${chatbot.apikey}")
21-
private String apikey1;
22-
23-
@Value("#{environment.CHATBOT_API_KEY}")
24-
private String apikey2;
19+
private String chatBotApiKey;
2520

2621
@RequestMapping("/")
2722
public @ResponseBody String greeting() {
2823
return "Hello World";
2924
}
3025

31-
@GetMapping("/get-chatbot-token")
26+
@PostMapping("/get-chatbot-token")
3227
@CrossOrigin(origins = {"http://localhost:8080", "http://localhost:8000", "https://gaebar.github.io"})
33-
public ObjectNode sayHello() throws IOException {
28+
public ObjectNode getChatBotToken() throws IOException {
3429
HttpURLConnection con = (HttpURLConnection) new URL("https://webchat.botframework.com/api/tokens").openConnection();
3530
con.setRequestMethod("GET");
36-
con.setRequestProperty("Authorization", "BotConnector " + apikey1);
31+
con.setRequestProperty("Authorization", "BotConnector " + chatBotApiKey);
3732

3833
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
3934
String output;

complete/src/test/java/hello/GreetingControllerTest.java renamed to complete/src/test/java/gettoken/GetTokenControllerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package hello;
16+
package gettoken;
1717

1818
import static org.hamcrest.Matchers.containsString;
1919
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -32,15 +32,15 @@
3232
@ExtendWith(SpringExtension.class)
3333
@SpringBootTest
3434
@AutoConfigureMockMvc
35-
public class GreetingControllerTest {
35+
public class GetTokenControllerTest {
3636

37-
@Autowired
38-
private MockMvc mockMvc;
37+
@Autowired
38+
private MockMvc mockMvc;
3939

40-
@Test
41-
public void greetingShouldReturnDefaultMessage() throws Exception {
40+
@Test
41+
public void greetingShouldReturnDefaultMessage() throws Exception {
4242

43-
this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk())
44-
.andExpect(content().string(containsString("Hello World")));
45-
}
43+
this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk())
44+
.andExpect(content().string(containsString("Hello World")));
45+
}
4646
}

0 commit comments

Comments
 (0)