Skip to content

Commit

Permalink
Merge remote branch 'fork/291'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Sep 16, 2014
2 parents d04da2c + cd67e30 commit 0f25db6
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,19 @@
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aspects</artifactId>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-github</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/com/thindeck/steps/ReadConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2014, Thindeck.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the thindeck.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.thindeck.steps;

import com.jcabi.aspects.Immutable;
import com.jcabi.github.Github;
import com.thindeck.api.Context;
import com.thindeck.api.Step;
import java.io.IOException;

/**
* Read repository configuration.
*
* @author Carlos Miranda ([email protected])
* @version $Id$
* @since 0.3
*/
@Immutable
public final class ReadConfig implements Step {

/**
* Public ctor.
* @param ghub Github instance.
*/
@SuppressWarnings("PMD.UnusedFormalParameter")
public ReadConfig(final Github ghub) {
throw new UnsupportedOperationException("Not yet implemented.");
}

@Override
public String name() {
return "read-config";
}

@Override
public void exec(final Context ctx) throws IOException {
throw new UnsupportedOperationException("exec: Not yet implemented");
}
@Override
public void commit(final Context ctx) {
// nothing to commit
}

@Override
public void rollback(final Context ctx) {
// nothing to rollback
}
}
101 changes: 101 additions & 0 deletions src/test/java/com/thindeck/steps/ReadConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (c) 2014, Thindeck.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the thindeck.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.thindeck.steps;

import com.google.common.base.Joiner;
import com.jcabi.github.Github;
import com.jcabi.github.Repo;
import com.jcabi.github.mock.MkGithub;
import com.jcabi.matchers.XhtmlMatchers;
import com.thindeck.api.Context;
import com.thindeck.api.Step;
import com.thindeck.api.mock.MkContext;
import javax.json.Json;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
import org.xembly.Directives;

/**
* Test case for {@link ReadConfig}.
*
* @author Carlos Miranda ([email protected])
* @version $Id$
* @since 0.3
*/
public final class ReadConfigTest {

/**
* Fetch repo configuration and update memo accordingly.
* @throws Exception If something goes wrong
* @todo #291 This test is currently ignored because ReadConfig is not yet
* implemented. Let's implement it, and have it read the info from the
* .thindeck.yml file of the repository root and update the Memo XML. See
* https://github.com/yegor256/thindeck/issues/291 for further details.
*/
@Test
@org.junit.Ignore
public void fetchesRepoConfigAndUpdatesMemo() throws Exception {
final Github ghub = new MkGithub("thindeck");
final Repo repo = ghub.repos().create(
Json.createObjectBuilder()
.add("name", "test")
.build()
);
final String config = Joiner.on('\n').join(
"domains: [\"example.com\", \"test.example.com\"]",
"ports: [80, 443]"
);
repo.contents().create(
Json.createObjectBuilder()
.add("path", ".thindeck.yml")
.add("message", "Thindeck config")
.add("content", config)
.build()
);
final Context ctx = new MkContext();
ctx.memo().update(
new Directives()
.add("/memo")
.add("/repo")
.add("/uri").set("[email protected]:thindeck/test.git")
);
final Step step = new ReadConfig(ghub);
step.exec(ctx);
MatcherAssert.assertThat(
ctx.memo().read(),
XhtmlMatchers.hasXPaths(
"//memo/domains/domain[.='example.com']",
"//memo/domains/domain[.='test.example.com']",
"//memo/ports/port[.='80']",
"//memo/ports/port[.='443']"
)
);
}
}

0 comments on commit 0f25db6

Please sign in to comment.