package voot.provider;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import voot.VootServiceApplication;
import voot.valueobject.Group;
import voot.valueobject.Membership;

import javax.sql.DataSource;
import java.util.List;

import static java.util.stream.Collectors.toList;
import static org.junit.Assert.*;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = VootServiceApplication.class)
@WebIntegrationTest(value = "flyway.enabled=true")
public class GrouperDaoClientTest {

  public static final String PREFIX = "urn:collab:group:grouper:";

  private GrouperDaoClient subject;

  @Autowired
  private DataSource dataSource;

  @Before
  public void setUp() throws Exception {
    subject = new GrouperDaoClient(new JdbcTemplate(dataSource), "grouper", PREFIX);

  }

  @Test
  public void testGroups() throws Exception {
    List<Group> groups = subject.groups("urn:collab:person:example.com:amin");
    assertEquals(5, groups.size());
    assertMembership(groups, PREFIX + "nl:surfnet:diensten:bazenteam", Membership.ADMIN);
    assertMembership(groups, PREFIX + "nl:surfnet:diensten:bassie_&_adriaan", Membership.ADMIN);
    assertMembership(groups, PREFIX + "nl:surfnet:diensten:burr", Membership.MANAGER);
    assertMembership(groups, PREFIX + "nl:surfnet:diensten:managementvo", Membership.MANAGER);
    assertMembership(groups, PREFIX + "nl:surfnet:diensten:test123", Membership.MEMBER);
  }

  private void assertMembership(List<Group> groups, String groupId, Membership membership) {
    assertEquals(groupId, groups.stream().filter(group -> group.id.equals(groupId)).collect(toList()).get(0).membership, membership);
  }
}

@@ -1772,16 +1772,683 @@
 MEMBER);
+%0A%0A    assertDisplayName(groups, PREFIX + %22nl:surfnet:diensten:bassie_&_adriaan%22, %22bassie & adriaan%22);%0A    assertDisplayName(groups, PREFIX + %22nl:surfnet:diensten:bazenteam%22, %22Bazenteam%22);%0A    assertDisplayName(groups, PREFIX + %22nl:surfnet:diensten:burr%22, %22burr%22);%0A    assertDisplayName(groups, PREFIX + %22nl:surfnet:diensten:test123%22, %22test123%22);%0A%0A    assertDescription(groups, PREFIX + %22nl:surfnet:diensten:bazenteam%22, %22Eh%22);%0A    assertDescription(groups, PREFIX + %22nl:surfnet:diensten:burr%22, %22fffff%22);%0A    assertDescription(groups, PREFIX + %22nl:surfnet:diensten:test123%22, %22Testteam%22);%0A%0A    assertSourceID(groups, PREFIX + %22nl:surfnet:diensten:bazenteam%22, %22grouper%22);
 %0A  %7D%0A%0A  
@@ -2563,16 +2563,28 @@
 groupId,
+ membership,
  groups.
@@ -2669,28 +2669,700 @@
 mbership
-, membership
+);%0A  %7D%0A%0A  private void assertDisplayName(List%3CGroup%3E groups, String groupId, String displayName) %7B%0A    assertEquals(groupId, displayName, groups.stream().filter(group -%3E group.id.equals(groupId)).collect(toList()).get(0).displayName);%0A  %7D%0A%0A  private void assertDescription(List%3CGroup%3E groups, String groupId, String description) %7B%0A    assertEquals(groupId, description, groups.stream().filter(group -%3E group.id.equals(groupId)).collect(toList()).get(0).description);%0A  %7D%0A%0A  private void assertSourceID(List%3CGroup%3E groups, String groupId, String sourceID) %7B%0A    assertEquals(groupId, sourceID, groups.stream().filter(group -%3E group.id.equals(groupId)).collect(toList()).get(0).sourceID
 );%0A  %7D%0A%7D

Add tests for group name, description and sourceid in GrouperDao.