Commit 017139b3 authored by Khalid Ali's avatar Khalid Ali

Correctly added GET for listings with some tests.

parent 09267cbc
......@@ -19,7 +19,6 @@ public class ListingService {
}
public List<ListingEntity> getAll() {
return listingRepository.findAll();
}
......
......@@ -7,8 +7,10 @@ import com.gmu.bookshare.service.ListingService;
import com.gmu.bookshare.service.ShareUserService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.awt.*;
import java.text.ParseException;
import java.util.List;
import java.util.stream.Collectors;
......@@ -31,7 +33,7 @@ public class BookshareApiController {
this.shareUserService = shareUserService;
}
@GetMapping(value = "/listing/")
@GetMapping(value = "/listing/", produces = MediaType.APPLICATION_JSON_VALUE)
List<ListingDto> getListings() {
List<ListingEntity> listings = listingService.getAll();
return listings.stream()
......
......@@ -52,7 +52,7 @@ public class BookshareRestControllerIntegrationTest {
given(listingService.getAll()).willReturn(allListingEntities);
mvc.perform(get("/bs/api/listing")
mvc.perform(get("/bs/api/listing/")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(1)))
......
package com.gmu.bookshare;
package com.gmu.bookshare.repository;
import com.gmu.bookshare.entity.ListingEntity;
import com.gmu.bookshare.persistence.ListingRepository;
......
package com.gmu.bookshare;
package com.gmu.bookshare.service;
import com.gmu.bookshare.entity.ListingEntity;
import com.gmu.bookshare.persistence.ListingRepository;
......@@ -9,7 +9,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
......@@ -18,11 +20,23 @@ import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest
//@SpringBootTest
public class ListingEntityServiceIntegrationTest {
@MockBean
private ListingRepository listingRepository;
@TestConfiguration
static class EmployeeServiceImplTestContextConfiguration {
@MockBean
public static ListingRepository listingRepository;
@Bean
public ListingService employeeService() {
return new ListingService(listingRepository);
}
}
// @MockBean
// private ListingRepository listingRepository;
@Autowired
private ListingService listingService;
......@@ -35,7 +49,7 @@ public class ListingEntityServiceIntegrationTest {
ArrayList<ListingEntity> l = new ArrayList<>();
l.add(listingEntity1);
Mockito.when(listingRepository.findByIsbn(listingEntity1.getIsbn()))
Mockito.when(EmployeeServiceImplTestContextConfiguration.listingRepository.findByIsbn(listingEntity1.getIsbn()))
.thenReturn(l);
}
......@@ -44,7 +58,6 @@ public class ListingEntityServiceIntegrationTest {
int isbn = 123456;
ListingEntity found = listingService.getIsbn(isbn);
assertThat(found.getIsbn())
.isEqualTo(isbn);
assertThat(found.getIsbn()).isEqualTo(isbn);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment