test/roles/RestrictAnnotationActionTest.java
@Test
    public void attemptToShowAdminPage() {
        Map<String, String> formData = new HashMap<>();
        formData.put("email", "john@gmail.com");
        formData.put("password", "password");

        Http.RequestBuilder request = Helpers.fakeRequest()
                .method("POST")
                .uri("/login")
                .bodyForm(formData);

        Result result = Helpers.route(TestApplication.getApplication(), request);

        request = Helpers.fakeRequest()
                .method(GET)
                .uri("/admin/admins/0")
                .session("connected", "1");

        result = Helpers.route(TestApplication.getApplication(),request);
        assertEquals(303, result.status());
    }
/**
     * Testing profile GET endpoint /admin.
     * Should send redirect as this user is non-admin.
     * This tests the annotation as the whole admin controller is restricted by the custom annotation.
     */
Testing profile GET endpoint /admin.
Should send redirect as this user is non-admin.
This tests the annotation as the whole admin controller is restricted by the custom annotation.
Testing profile GET endpoint / admin . Should send redirect as this user is non - admin . This tests the annotation as the whole admin controller is restricted by the custom annotation .
@Test
    public void attemptToShowAdminPage() {
        Map<String, String> formData = new HashMap<>();
        formData.put("email", "john@gmail.com");
        formData.put("password", "password");
        Http.RequestBuilder request = Helpers.fakeRequest()
                .method("POST")
                .uri("/login")
                .bodyForm(formData);
        Result result = Helpers.route(TestApplication.getApplication(), request);
        request = Helpers.fakeRequest()
                .method(GET)
                .uri("/admin/admins/0")
                .session("connected", "1");
        result = Helpers.route(TestApplication.getApplication(),request);
        assertEquals(303, result.status());
    }
@ Test public void attemptToShowAdminPage ( ) { Map < String , String > formData = new HashMap < > ( ) ; formData . put ( "email" , "john@gmail.com" ) ; formData . put ( "password" , "password" ) ; Http . RequestBuilder request = Helpers . fakeRequest ( ) . method ( "POST" ) . uri ( "/login" ) . bodyForm ( formData ) ; Result result = Helpers . route ( TestApplication . getApplication ( ) , request ) ; request = Helpers . fakeRequest ( ) . method ( GET ) . uri ( "/admin/admins/0" ) . session ( "connected" , "1" ) ; result = Helpers . route ( TestApplication . getApplication ( ) , request ) ; assertEquals ( 303 , result . status ( ) ) ; }
Testing profile GET endpoint /admin.
Testing profile GET endpoint / admin .