package org.dotwebstack.framework.frontend.ld.representation;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

import org.dotwebstack.framework.backend.BackendSource;
import org.dotwebstack.framework.frontend.http.site.Site;
import org.dotwebstack.framework.frontend.http.stage.Stage;
import org.dotwebstack.framework.informationproduct.InformationProduct;
import org.dotwebstack.framework.test.DBEERPEDIA;
import org.junit.Assert;
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.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class RepresentationTest {

  @Rule
  public final ExpectedException thrown = ExpectedException.none();

  @Mock
  BackendSource backendSource;

  @Mock
  Site site;

  @Test
  public void builder() {
    // Act
    final Representation representation =
        new Representation.Builder(DBEERPEDIA.BREWERIES, DBEERPEDIA.URL_PATTERN.stringValue())
            .build();

    // Assert
    assertThat(representation.getIdentifier(), equalTo(DBEERPEDIA.BREWERIES));
    assertThat(representation.getInformationProduct(), equalTo(null));
    assertThat(representation.getStage(), equalTo(null));
    Assert.assertNotNull(representation.getUrlPatterns());
  }

  @Test
  public void builderWithoutUrlPatterns() {
    // Act
    final Representation representation =
        new Representation.Builder(DBEERPEDIA.BREWERIES)
            .build();

    // Assert
    assertThat(representation.getIdentifier(), equalTo(DBEERPEDIA.BREWERIES));
    assertThat(representation.getInformationProduct(), equalTo(null));
    assertThat(representation.getStage(), equalTo(null));
    Assert.assertNotNull(representation.getUrlPatterns());
  }

  @Test
  public void builderWithUrlPattern() {
    // Act
    final Representation representation = new Representation.Builder(DBEERPEDIA.BREWERIES,
        DBEERPEDIA.URL_PATTERN.stringValue()).build();

    // Assert
    assertThat(representation.getIdentifier(), equalTo(DBEERPEDIA.BREWERIES));

    assertThat(representation.getUrlPatterns().toArray()[0],
        equalTo(DBEERPEDIA.URL_PATTERN.stringValue()));
  }

  @Test
  public void builderMultipleUrlPatterns() {
    // Act
    final Representation representation =
        new Representation.Builder(DBEERPEDIA.BREWERIES, DBEERPEDIA.URL_PATTERN.stringValue(),
            DBEERPEDIA.URL_PATTERN.stringValue(),
            DBEERPEDIA.URL_PATTERN.stringValue())
            .build();

    // Assert
    assertThat(representation.getIdentifier(), equalTo(DBEERPEDIA.BREWERIES));
    assertThat(representation.getInformationProduct(), equalTo(null));
    assertThat(representation.getStage(), equalTo(null));
    assertThat(representation.getUrlPatterns().toArray()[0],
        equalTo(DBEERPEDIA.URL_PATTERN.stringValue()));
    assertThat(representation.getUrlPatterns().size(), equalTo(3));
  }

  @Test
  public void builderComplete() {
    // Act
    final InformationProduct informationProduct =
        new InformationProduct.Builder(DBEERPEDIA.BREWERIES, backendSource).label(
            DBEERPEDIA.BREWERIES_LABEL.stringValue()).build();

    final Stage stage = new Stage.Builder(DBEERPEDIA.BREWERIES, site).basePath(
        DBEERPEDIA.BASE_PATH.stringValue()).build();

    final Representation representation =
        new Representation.Builder(DBEERPEDIA.BREWERIES, DBEERPEDIA.URL_PATTERN.stringValue())
            .informationProduct(informationProduct)
            .stage(stage)
            .build();

    // Assert
    assertThat(representation.getIdentifier(), equalTo(DBEERPEDIA.BREWERIES));
    assertThat(representation.getInformationProduct(), equalTo(informationProduct));
    assertThat(representation.getStage(), equalTo(stage));
    assertThat(representation.getUrlPatterns().toArray()[0],
        equalTo(DBEERPEDIA.URL_PATTERN.stringValue()));
    assertThat(representation.getUrlPatterns().size(), equalTo(1));
  }

  @Test
  public void builderWithNullValues() {
    // Assert
    thrown.expect(NullPointerException.class);

    // Act
    final Representation representation =
        new Representation.Builder(DBEERPEDIA.BREWERIES, null).build();
  }

}

@@ -953,32 +953,24 @@
 esentation =
-%0A       
  new Represe
@@ -998,32 +998,40 @@
 PEDIA.BREWERIES,
+%0A       
  DBEERPEDIA.URL_
@@ -1048,37 +1048,24 @@
 ringValue())
-%0A            
 .build();%0A%0A 
@@ -1449,32 +1449,24 @@
 esentation =
-%0A       
  new Represe
@@ -1502,29 +1502,16 @@
 EWERIES)
-%0A            
 .build()
@@ -2467,36 +2467,24 @@
 ringValue(),
-%0A           
  DBEERPEDIA.
@@ -2509,29 +2509,16 @@
 Value())
-%0A            
 .build()
@@ -3353,32 +3353,24 @@
 esentation =
-%0A       
  new Represe
@@ -3398,32 +3398,40 @@
 PEDIA.BREWERIES,
+%0A       
  DBEERPEDIA.URL_
@@ -3452,29 +3452,16 @@
 Value())
-%0A            
 .informa
@@ -3495,34 +3495,15 @@
 uct)
-%0A            
 .stage(
-stage)
 %0A   
@@ -3511,16 +3511,22 @@
         
+stage)
 .build()
@@ -3874,32 +3874,32 @@
 tringValue()));%0A
+
     assertThat(r
@@ -3959,246 +3959,6 @@
  %7D%0A%0A
-  @Test%0A  public void builderWithNullValues() %7B%0A    // Assert%0A    thrown.expect(NullPointerException.class);%0A%0A    // Act%0A    final Representation representation =%0A        new Representation.Builder(DBEERPEDIA.BREWERIES, null).build();%0A  %7D%0A%0A
 %7D%0A

Remove obsolete test causing warnings