Skip to content

Commit

Permalink
Merge pull request #12 from aleksandr-kotlyar/sitemapurl-property
Browse files Browse the repository at this point in the history
Set sitemapUrl property in pom and through gitlab-ci (Resolves #11)
  • Loading branch information
aleksandr-kotlyar authored Feb 23, 2020
2 parents f7cda6a + b17dff6 commit d642689
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ image: registry.gitlab.com/aleksandr-kotlyar/java-sitemap-checker
stages:
- test

variables:
SITEMAPURL: https://www.ivi.ru/sitemap-series-adventures.xml #default sitemapUrl

test:
stage: test
script:
- mvn clean test
- mvn clean test -DsitemapUrl=${SITEMAPURL}
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@

<groupId>java-sitemap-checker</groupId>
<artifactId>java-sitemap-checker</artifactId>
<version>1.3-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sitemapUrl>https://www.ivi.ru/sitemap-series-adventures.xml</sitemapUrl>
</properties>

<build>

<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -43,18 +52,21 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>

<dependency>
Expand All @@ -67,7 +79,6 @@
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
<scope>test</scope>
</dependency>

<!-- replace dependencies that have been removed from JRE's starting with Java v11 -->
Expand Down
21 changes: 19 additions & 2 deletions src/test/java/sitemap/tests/SitemapTest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package sitemap.tests;

import sitemap.StepsLogger;
import io.restassured.response.Response;
import org.assertj.core.api.SoftAssertions;
import org.jsoup.Jsoup;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import sitemap.StepsLogger;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import static io.restassured.RestAssured.given;

/**
* Created by Aleksandr Kotlyar on 09.11.2017. 21:44
*/
public class SitemapTest extends StepsLogger {
private static final String SITEMAP_URL = "https://qiwi.com/sitemap.xml";
private static String SITEMAP_PAGE_SOURCE;
private String SITEMAP_URL;
private List<String> allSitemapLinks = new ArrayList<>();
private SoftAssertions softAssertions = new SoftAssertions();

@Before
public void checkSitemapIsAvailable() throws Exception {
SITEMAP_URL = getSitemapUrl();
given().header("user-agent", "yandex").when().get(SITEMAP_URL).then().statusCode(200);
}

Expand Down Expand Up @@ -52,4 +56,17 @@ private void assertStatusCode(String link) {
info(String.format("%2d;%s", response.statusCode(), link));
softAssertions.assertThat(response.statusCode()).as("link: '" + link + "'").isEqualTo(200);
}

private String getSitemapUrl() {
Properties properties = new Properties();
try {
properties.load(SitemapTest.class.getClassLoader().getResourceAsStream("Sitemap.properties"));
} catch (IOException e) {
e.printStackTrace();
Assert.fail();
}
String url = properties.getProperty("sitemapUrl");
Assert.assertNotEquals("Target url is empty! Set sitemapUrl in pom.xml or ${SITEMAPURL} in Gitlab-CI", "", url);
return url;
}
}
1 change: 1 addition & 0 deletions src/test/resources/Sitemap.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sitemapUrl=${sitemapUrl}

0 comments on commit d642689

Please sign in to comment.