forked from yegor256/takes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yegor Bugayenko
committed
Mar 4, 2015
1 parent
34cf8fb
commit 90796fd
Showing
6 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.takes.ts; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import org.takes.Request; | ||
import org.takes.Take; | ||
import org.takes.Takes; | ||
import org.takes.tk.TkEmpty; | ||
|
||
/** | ||
* Empty. | ||
* | ||
* @author Yegor Bugayenko (yegor@teamed.io) | ||
* @version $Id$ | ||
* @since 0.4 | ||
*/ | ||
@EqualsAndHashCode | ||
public class TsEmpty implements Takes { | ||
|
||
@Override | ||
public final Take route(final Request request) { | ||
return new TkEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.takes.ts; | ||
|
||
import java.util.ResourceBundle; | ||
import lombok.EqualsAndHashCode; | ||
import org.takes.Takes; | ||
|
||
/** | ||
* Takes that adds an HTTP header to each response with a version | ||
* of Takes framework. | ||
* | ||
* @author Yegor Bugayenko (yegor@teamed.io) | ||
* @version $Id$ | ||
* @since 0.4 | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
public final class TsVersioned extends TsWrap { | ||
|
||
/** | ||
* Version of the library. | ||
*/ | ||
private static final String VERSION = TsVersioned.make(); | ||
|
||
/** | ||
* Ctor. | ||
* @param takes Original takes | ||
*/ | ||
public TsVersioned(final Takes takes) { | ||
this(takes, "X-Takes-Version"); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param takes Original takes | ||
* @param header Header to add | ||
*/ | ||
public TsVersioned(final Takes takes, final String header) { | ||
super(new TsWithHeaders(takes).with(header, TsVersioned.VERSION)); | ||
} | ||
|
||
/** | ||
* Make a version. | ||
* @return Version | ||
*/ | ||
private static String make() { | ||
final ResourceBundle res = | ||
ResourceBundle.getBundle("org.takes.version"); | ||
return String.format( | ||
"%s %s built on %s", | ||
res.getString("version"), | ||
res.getString("revision"), | ||
res.getString("date") | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.takes.ts; | ||
|
||
import java.io.IOException; | ||
import lombok.EqualsAndHashCode; | ||
import org.takes.Request; | ||
import org.takes.Take; | ||
import org.takes.Takes; | ||
|
||
/** | ||
* Wrap of takes. | ||
* | ||
* @author Yegor Bugayenko (yegor@teamed.io) | ||
* @version $Id$ | ||
* @since 0.4 | ||
*/ | ||
@EqualsAndHashCode(of = "origin") | ||
public class TsWrap implements Takes { | ||
|
||
/** | ||
* Original takes. | ||
*/ | ||
private final transient Takes origin; | ||
|
||
/** | ||
* Ctor. | ||
* @param takes Original takes | ||
*/ | ||
public TsWrap(final Takes takes) { | ||
this.origin = takes; | ||
} | ||
|
||
@Override | ||
public final Take route(final Request request) throws IOException { | ||
return this.origin.route(request); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version=${project.version} | ||
revision=${buildNumber} | ||
date=${timestamp} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.takes.ts; | ||
|
||
import java.io.IOException; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
import org.takes.rq.RqFake; | ||
import org.takes.rs.RsPrint; | ||
|
||
/** | ||
* Test case for {@link TsVersioned}. | ||
* @author Yegor Bugayenko (yegor@teamed.io) | ||
* @version $Id$ | ||
* @since 0.4 | ||
*/ | ||
public final class TsVersionedTest { | ||
|
||
/** | ||
* TsVersioned can add a header with version name. | ||
* @throws IOException If some problem inside | ||
*/ | ||
@Test | ||
public void attachesHeader() throws IOException { | ||
MatcherAssert.assertThat( | ||
new RsPrint( | ||
new TsVersioned(new TsEmpty()).route( | ||
new RqFake() | ||
).act() | ||
).print(), | ||
Matchers.containsString("X-Takes-Version") | ||
); | ||
} | ||
|
||
} |