Elffuss BraidHub

kikocis/java-driver public

b0183766246b · 3.3 KiBRawPermalink
1/*
2 * Copyright (C) 2012-2015 DataStax Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.datastax.driver.osgi;
17
18import org.ops4j.pax.exam.Configuration;
19import org.ops4j.pax.exam.Option;
20import org.ops4j.pax.exam.testng.listener.PaxExam;
21import org.testng.annotations.Listeners;
22import org.testng.annotations.Test;
23
24import static org.ops4j.pax.exam.CoreOptions.options;
25import static org.testng.Assert.assertTrue;
26import static org.testng.Assert.fail;
27
28import com.datastax.driver.core.Cluster;
29
30import static com.datastax.driver.osgi.BundleOptions.defaultOptions;
31import static com.datastax.driver.osgi.BundleOptions.driverBundle;
32import static com.datastax.driver.osgi.BundleOptions.guavaBundle;
33import static com.datastax.driver.osgi.BundleOptions.nettyBundles;
34
35@Listeners({PaxExam.class})
36@Test(groups="short")
37public class GuavaSanityCheckNegativeIT {
38
39 @Configuration
40 public Option[] guava14_0_1Config() {
41 return options(
42 driverBundle(),
43 nettyBundles(),
44 guavaBundle().version("14.0.1"),
45 defaultOptions()
46 );
47 }
48
49 @Configuration
50 public Option[] guava15Config() {
51 return options(
52 driverBundle(),
53 nettyBundles(),
54 guavaBundle().version("15.0"),
55 defaultOptions()
56 );
57 }
58
59 @Configuration
60 public Option[] guava16Config() {
61 return options(
62 driverBundle(),
63 nettyBundles(),
64 guavaBundle().version("16.0"),
65 defaultOptions()
66 );
67 }
68
69 /**
70 * <p>
71 * Validates that the driver is able to detect that the guava library in the classpath is
72 * less than version 16.01 and throws an {@link IllegalStateException} in this case and
73 * is raised as the cause of an {@link ExceptionInInitializerError} since the failure
74 * occurs at static initialization.
75 * </p>
76 *
77 * The following configurations are tried (defined via methods with the @Configuration annotation):
78 * <ol>
79 * <li>With Guava 14.0.1</li>
80 * <li>With Guava 15.0</li>
81 * <li>With Guava 16.0</li>
82 * </ol>
83 *
84 * @test_category packaging
85 * @expected_result An {@link IllegalStateException} is thrown.
86 * @jira_ticket JAVA-961
87 * @since 3.0.0-beta1
88 */
89 public void should_raise_guava_version_error_if_lt_16_0_1() throws Throwable {
90 try {
91 Cluster.builder();
92 fail("Expected an IllegalStateException for Guava version incompatibility");
93 }
94 catch(ExceptionInInitializerError e) {
95 try {
96 throw e.getCause();
97 } catch(IllegalStateException ise) {
98 assertTrue(ise.getMessage().contains("Detected Guava issue #1635"));
99 }
100 }
101 }
102}