<commit_before>package sg.ncl;

import org.apache.commons.lang3.RandomStringUtils;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
import sg.ncl.domain.NodeType;
import sg.ncl.domain.UserType;
import sg.ncl.testbed_interface.User2;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;


/**
 * @author <NAME>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = WebApplication.class)
@WebAppConfiguration
public class MainControllerTest {

    @Rule
    public MockitoRule mockito = MockitoJUnit.rule();
    @Rule
    public ExpectedException exception = ExpectedException.none();

//    @Bean
//    RestTemplate restTemplate() {
//        return Mockito.mock(RestTemplate.class);
//    }

    private MockMvc mockMvc;
//    private RestTemplate restTemplate;
    private MockRestServiceServer mockServer;

    @Inject
    private RestOperations restOperations;

    @Inject
    private ConnectionProperties properties;

    @Inject
    private WebApplicationContext webApplicationContext;

    @Mock
    private WebProperties webProperties;

    @Mock
    private HttpSession session;

    @Before
    public void setUp() throws Exception {
//        restTemplate = Mockito.mock(RestTemplate.class);
        mockServer = MockRestServiceServer.createServer((RestTemplate) restOperations);
        mockMvc = webAppContextSetup(webApplicationContext).build();
    }

    //--------------------------------------
    // Test before login HTML pages
    //--------------------------------------
    @Test
    public void testIndexPage() throws Exception {
        // ensure page can load <head>, navigation, <body>, <footer>
        mockMvc.perform(get("/"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("NATIONAL CYBERSECURITY R&amp;D LAB")))
                .andExpect(content().string(containsString("Features")))
                .andExpect(content().string(containsString("Focus on your")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testOverviewPage() throws Exception {
        mockMvc.perform(get("/overview"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("id=\"joinUs\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testCommunityPage() throws Exception {
        mockMvc.perform(get("/community"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testAboutPage() throws Exception {
        mockMvc.perform(get("/about"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("id=\"about-us\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testEventPage() throws Exception {
        mockMvc.perform(get("/event"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("div id=\"portfolioSlider\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testPlanPage() throws Exception {
        mockMvc.perform(get("/plan"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    // page is taken out as of 22/9/2016
    @Ignore
    public void testFuturePlanPage() throws Exception {
        mockMvc.perform(get("/futureplan"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("a href=\"/futureplan/download\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testPricingPage() throws Exception {
        mockMvc.perform(get("/pricing"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("Pricing")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testResourcesPage() throws Exception {
        mockMvc.perform(get("/resources"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testResearchPage() throws Exception {
        mockMvc.perform(get("/research"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("Research")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testCalendarPage() throws Exception {
        // calendar page display BEFORE login
        mockMvc.perform(get("/calendar"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("iframe src=\"https://calendar.google.com/calendar/embed")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testContactUsPage() throws Exception {
        // calendar page display BEFORE login
        mockMvc.perform(get("/contactus"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("Contact Us")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testGetLoginPage() throws Exception {
        mockMvc.perform(get("/login"))
                .andExpect(status().isOk())
                .andExpect(view().name("login"))
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("/login")))
                .andExpect(content().string(containsString("/signup2")))
                .andExpect(content().string(containsString("form method=\"post\" action=\"/login\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }<commit_msg>Remove calendar unit test<commit_after>package sg.ncl;

import org.apache.commons.lang3.RandomStringUtils;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
import sg.ncl.domain.NodeType;
import sg.ncl.domain.UserType;
import sg.ncl.testbed_interface.User2;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;


/**
 * @author <NAME>
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = WebApplication.class)
@WebAppConfiguration
public class MainControllerTest {

    @Rule
    public MockitoRule mockito = MockitoJUnit.rule();
    @Rule
    public ExpectedException exception = ExpectedException.none();

//    @Bean
//    RestTemplate restTemplate() {
//        return Mockito.mock(RestTemplate.class);
//    }

    private MockMvc mockMvc;
//    private RestTemplate restTemplate;
    private MockRestServiceServer mockServer;

    @Inject
    private RestOperations restOperations;

    @Inject
    private ConnectionProperties properties;

    @Inject
    private WebApplicationContext webApplicationContext;

    @Mock
    private WebProperties webProperties;

    @Mock
    private HttpSession session;

    @Before
    public void setUp() throws Exception {
//        restTemplate = Mockito.mock(RestTemplate.class);
        mockServer = MockRestServiceServer.createServer((RestTemplate) restOperations);
        mockMvc = webAppContextSetup(webApplicationContext).build();
    }

    //--------------------------------------
    // Test before login HTML pages
    //--------------------------------------
    @Test
    public void testIndexPage() throws Exception {
        // ensure page can load <head>, navigation, <body>, <footer>
        mockMvc.perform(get("/"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("NATIONAL CYBERSECURITY R&amp;D LAB")))
                .andExpect(content().string(containsString("Features")))
                .andExpect(content().string(containsString("Focus on your")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testOverviewPage() throws Exception {
        mockMvc.perform(get("/overview"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("id=\"joinUs\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testCommunityPage() throws Exception {
        mockMvc.perform(get("/community"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testAboutPage() throws Exception {
        mockMvc.perform(get("/about"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("id=\"about-us\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testEventPage() throws Exception {
        mockMvc.perform(get("/event"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("div id=\"portfolioSlider\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testPlanPage() throws Exception {
        mockMvc.perform(get("/plan"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    // page is taken out as of 22/9/2016
    @Ignore
    public void testFuturePlanPage() throws Exception {
        mockMvc.perform(get("/futureplan"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("a href=\"/futureplan/download\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testPricingPage() throws Exception {
        mockMvc.perform(get("/pricing"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("Pricing")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testResourcesPage() throws Exception {
        mockMvc.perform(get("/resources"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testResearchPage() throws Exception {
        mockMvc.perform(get("/research"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("Research")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testContactUsPage() throws Exception {
        // calendar page display BEFORE login
        mockMvc.perform(get("/contactus"))
                .andExpect(status().isOk())
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("navbar-header")))
                .andExpect(content().string(containsString("Contact Us")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }

    @Test
    public void testGetLoginPage() throws Exception {
        mockMvc.perform(get("/login"))
                .andExpect(status().isOk())
                .andExpect(view().name("login"))
                .andExpect(content().string(containsString("main.css")))
                .andExpect(content().string(containsString("main.js")))
                .andExpect(content().string(containsString("/login")))
                .andExpect(content().string(containsString("/signup2")))
                .andExpect(content().string(containsString("form method=\"post\" action=\"/login\"")))
                .andExpect(content().string(containsString("footer id=\"footer\"")));
    }
{'fraction_non_alphanumeric': 0.1479090909090909, 'fraction_numerical': 0.0011818181818181819, 'mean_word_length': 3.113874345549738, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2392308', 'n_tokens_mistral': 5835, 'n_tokens_neox': 5645, 'n_words': 785}