¿Cómo usar mockito para probar un servicio REST?

Soy muy nuevo en Java Unit Testing y escuché que el framework Mockito es realmente bueno para propósitos de prueba.

He desarrollado un servidor REST (métodos CRUD) y ahora quiero probarlo, pero no sé cómo.

Aún más, no sé cómo debería comenzar este procedimiento de prueba. Mi servidor debería funcionar en localhost y luego hacer llamadas en esa URL (por ejemplo, localhost: 8888).

Esto es lo que intenté hasta ahora, pero estoy bastante seguro de que esta no es la forma correcta.

    @Test
    public void testInitialize() {
        RESTfulGeneric rest = mock(RESTfulGeneric.class);

        ResponseBuilder builder = Response.status(Response.Status.OK);

        builder = Response.status(Response.Status.OK).entity(
                "Your schema was succesfully created!");

        when(rest.initialize(DatabaseSchema)).thenReturn(builder.build());

        String result = rest.initialize(DatabaseSchema).getEntity().toString();

        System.out.println("Here: " + result);

        assertEquals("Your schema was succesfully created!", result);

    }

Aquí está el código parainitialize método.

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/initialize")
    public Response initialize(String DatabaseSchema) {

        /** Set the LogLevel to Info, severe, warning and info will be written */
        LOGGER.setLevel(Level.INFO);

        ResponseBuilder builder = Response.status(Response.Status.OK);

        LOGGER.info("POST/initialize - Initialize the " + user.getUserEmail()
                + " namespace with a database schema.");

        /** Get a handle on the datastore itself */
        DatastoreService datastore = DatastoreServiceFactory
                .getDatastoreService();


        datastore.put(dbSchema);

        builder = Response.status(Response.Status.OK).entity(
                "Your schema was succesfully created!");
        /** Send response */
        return builder.build();
    }

En este caso de prueba, deseo enviar una cadena Json al servidor (POST). Si todo salió bien, el servidor debería responder con "¡Su esquema fue creado con éxito!".

¿Puede alguien ayudarme por favor?

Respuestas a la pregunta(5)

Su respuesta a la pregunta