Elffuss BraidHub

kikocis/java-driver public

ae54dea4aa32 · 3.9 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 java.util.ArrayList;
19import java.util.Collection;
20import java.util.GregorianCalendar;
21
22import javax.inject.Inject;
23import org.ops4j.pax.exam.Configuration;
24import org.ops4j.pax.exam.Option;
25import org.ops4j.pax.exam.testng.listener.PaxExam;
26import org.testng.annotations.Listeners;
27import org.testng.annotations.Test;
28
29import static org.ops4j.pax.exam.CoreOptions.options;
30import static org.testng.Assert.assertEquals;
31
32import com.datastax.driver.osgi.api.MailboxException;
33import com.datastax.driver.osgi.api.MailboxMessage;
34import com.datastax.driver.osgi.api.MailboxService;
35
36import static com.datastax.driver.osgi.BundleOptions.*;
37
38@Listeners({CCMBridgeListener.class, PaxExam.class})
39@Test(groups="short")
40public class MailboxServiceIT {
41 @Inject MailboxService service;
42
43 @Configuration
44 public Option[] shadedConfig() {
45 return options(
46 driverBundle(true),
47 mailboxBundle(),
48 guavaBundle(),
49 defaultOptions()
50 );
51 }
52
53 @Configuration
54 public Option[] defaultConfig() {
55 return options(
56 driverBundle(),
57 mailboxBundle(),
58 guavaBundle(),
59 nettyBundles(),
60 defaultOptions()
61 );
62 }
63
64 @Configuration
65 public Option[] guava17Config() {
66 return options(
67 driverBundle(),
68 mailboxBundle(),
69 nettyBundles(),
70 guavaBundle().version("17.0"),
71 defaultOptions()
72 );
73 }
74
75 @Configuration
76 public Option[] guava18Config() {
77 return options(
78 driverBundle(),
79 mailboxBundle(),
80 nettyBundles(),
81 guavaBundle().version("18.0"),
82 defaultOptions()
83 );
84 }
85
86 /**
87 * <p>
88 * Exercises a 'mailbox' service provided by an OSGi bundle that depends on the driver. Ensures that
89 * queries can be made through the service with the current given configuration.
90 * </p>
91 *
92 * The following configurations are tried (defined via methods with the @Configuration annotation):
93 * <ol>
94 * <li>Default bundle (Driver with all of it's dependencies)</li>
95 * <li>Shaded bundle (Driver with netty shaded)</li>
96 * <li>With Guava 16.0.1</li>
97 * <li>With Guava 17</li>
98 * <li>With Guava 18</li>
99 * </ol>
100 *
101 * @test_category packaging
102 * @expected_result Can create, retrieve and delete data using the mailbox service.
103 * @jira_ticket JAVA-620
104 * @since 2.0.10, 2.1.5
105 */
106 public void service_api_functional() throws MailboxException {
107 // Insert some data into mailbox for a particular user.
108 String recipient = "user@datastax.com";
109
110 try {
111 Collection<MailboxMessage> inMessages = new ArrayList<MailboxMessage>();
112 for (int i = 0; i < 30; i++) {
113 MailboxMessage message = new MailboxMessage(recipient, new GregorianCalendar(2015, 1, i).getTime(), recipient, "" + i);
114 inMessages.add(message);
115 service.sendMessage(message);
116 }
117
118 Collection<MailboxMessage> messages = service.getMessages(recipient);
119
120 assertEquals(messages, inMessages);
121 } finally {
122 service.clearMailbox(recipient);
123 }
124 }
125}