Commit a4af119c authored by Øyvin Halfdan Thuv's avatar Øyvin Halfdan Thuv
Browse files

Adding basic Cassandra query code.

parent ed37a0e6
package statelessws;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -8,9 +12,34 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class IncidentController {
Cluster cluster;
Session session;
/*
* CREATE KEYSPACE storage WITH REPLICATION = {
* 'class': 'SimpleStrategy',
* 'replication_factor': 1
* };
*/
public IncidentController () {
cluster = Cluster.builder()
.addContactPoint("127.0.0.1").build();
session = cluster.connect("storage");
}
/*
* USE storage;
* CREATE TABLE incident ( id int PRIMARY KEY, name text );
* INSERT INTO incident (id, name) VALUES (0, 'Great incident');
*/
@RequestMapping("/incident")
public Incident incident() {
return new Incident(0, "Test");
ResultSet incidents = session.execute("SELECT * FROM incident");
Row incident = incidents.one();
return new Incident(incident.getInt("id"),
incident.getString("name"));
}
}
package statelessws;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class IncidentControllerTests {
@Autowired
private MockMvc mockMvc;
@Test
public void itWorks() throws Exception {
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment