Skip to content

Commit

Permalink
moved test data and deleted application from core
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsamson7 committed Oct 10, 2024
1 parent e06296d commit 051effe
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 79 deletions.
14 changes: 14 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>

<!-- test -->

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<!-- build -->
Expand Down
5 changes: 1 addition & 4 deletions dorm/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<scope>test</scope>
</dependency>

<!-- test -->
Expand All @@ -83,9 +83,6 @@
</dependencies>

<build>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>


<plugins>
<!-- antlr -->

Expand Down
18 changes: 5 additions & 13 deletions dorm/core/src/main/kotlin/org/sirius/dorm/DORMConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@ import org.sirius.dorm.json.ObjectModule
import com.fasterxml.jackson.databind.ObjectMapper
import org.sirius.dorm.model.json.ObjectDescriptorModule
import org.sirius.common.type.json.TypeModule
import org.sirius.dorm.session.DummySessionContextProvider
import org.sirius.dorm.session.SessionContext
import org.sirius.dorm.session.SessionContextProvider
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.domain.EntityScan
import org.springframework.boot.runApplication
import org.springframework.context.annotation.*

class DefaultSessionContextProvider : SessionContextProvider {
override fun getUser(): String {
return "me"
}
}

@Configuration
@ComponentScan
@EntityScan
class DORMConfiguration {
@Bean
@Primary
//@Bean
//@Primary
fun session() : SessionContext {
return SessionContext(DefaultSessionContextProvider())
return SessionContext(DummySessionContextProvider("me"))
}

@Bean
Expand All @@ -47,8 +43,4 @@ class DORMConfiguration {
// TODO....if we remove it, spring will not boot....

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
//runApplication<DemoApplication>(*args)
}
class DemoApplication
4 changes: 4 additions & 0 deletions dorm/core/src/main/kotlin/org/sirius/dorm/ObjectManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class ObjectManager() {
return TransactionState.current().create(objectDescriptor.create(Status.CREATED))
}

fun create(objectDescriptor: String) : DataObject {
return TransactionState.current().create(getDescriptor(objectDescriptor).create(Status.CREATED))
}

fun delete(obj: DataObject) {
obj.delete()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ class ObjectDescriptorBuilder(val manager: ObjectManager, val name: String) {

// public

fun register() {
fun register() : ObjectManager {
manager.register(ObjectDescriptor(name, properties.toTypedArray()))

return manager
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sirius.dorm.session
/*
* @COPYRIGHT (C) 2023 Andreas Ernst
*
* All rights reserved
*/

class DummySessionContextProvider(val userName: String) : SessionContextProvider {
override fun getUser(): String {
return userName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface SessionContextProvider {
fun getUser() : String
}

class SessionContext(val provider: SessionContextProvider) : SessionContextProvider {
open class SessionContext(val provider: SessionContextProvider) : SessionContextProvider {
// implement

override fun getUser(): String {
Expand Down
23 changes: 23 additions & 0 deletions dorm/core/src/test/kotlin/org/sirius/dorm/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,32 @@ abstract class AbstractTest {
.add(attribute("float").type(float()))
.add(attribute("double").type(double()))
.register()

.type("other-person")
.add(attribute("name").type(stringType))

// relations

.add(relation("father").target("other-person").multiplicity(Multiplicity.ZERO_OR_ONE).inverse("children"))
.add(relation("children").target("other-person").multiplicity(Multiplicity.ZERO_OR_MANY).inverse("father").owner())

}

personDescriptor = objectManager.getDescriptor("person")

val father = objectManager.create("other-person")

father["name"] = "Andi"

// child

val child = objectManager.create("other-person")

child["name"] = "Nika"

// link

child["father"] = father
}
}

Expand Down
4 changes: 0 additions & 4 deletions dorm/demo-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@
</dependencies>

<build>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>


<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -133,7 +130,6 @@
</compilerPlugins>

<sourceDirs>
<source>${basedir}/target/generated-sources/antlr4</source>
<source>src/main/kotlin</source>
<source>src/main/resources</source>
</sourceDirs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ package org.sirius.application
* All rights reserved
*/

//import lombok.extern.slf4j.Slf4j
import jakarta.annotation.PostConstruct
import org.sirius.dorm.DORMConfiguration
import org.sirius.dorm.ObjectManager
import org.sirius.dorm.graphql.test.TestData
import org.sirius.dorm.session.DummySessionContextProvider
import org.sirius.dorm.session.SessionContext
import org.sirius.dorm.session.SessionContextProvider
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.*
import org.springframework.stereotype.Component

@Component
class DummySessionContext : SessionContext(DummySessionContextProvider("me")) {}

class DefaultSessionContextProvider : SessionContextProvider {
override fun getUser(): String {
return "me"
}
}
@Configuration()
@ComponentScan
@Import(DORMConfiguration::class)
class ApplicationConfiguration {
@Bean
@Primary
fun session() : SessionContext {
return SessionContext(DefaultSessionContextProvider())
@Autowired
lateinit var objectManager: ObjectManager

@PostConstruct
fun createData() {
TestData(objectManager)
}
}

@SpringBootApplication
//@Slf4j
class DORMApplication {
companion object {
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component


@Component
class TestData {
@Autowired
lateinit var objectManager: ObjectManager
class TestData(val objectManager: ObjectManager) {
init {
setupData()
}

// protected
// private

protected fun <T> withTransaction(doIt: () -> T) : T {
private fun <T> withTransaction(doIt: () -> T) : T {
objectManager.begin()
var committed = false

Expand All @@ -42,7 +42,6 @@ class TestData {
}
}

@PostConstruct
fun setupData() {
withTransaction {
// create type
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import graphql.schema.idl.RuntimeWiring
import jakarta.annotation.PostConstruct
import org.sirius.dorm.ObjectManager
import org.sirius.dorm.graphql.scalars.LocalDateTimeScalar
import org.sirius.dorm.graphql.test.TestData
//TODO import org.sirius.dorm.graphql.test.TestData
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component
Expand All @@ -20,8 +20,8 @@ import org.springframework.stereotype.Component
class GraphQLProvider {
// instance data

@Autowired
lateinit var test : TestData
//@Autowired
//lateinit var test : TestData

@Autowired
lateinit var objectManager : ObjectManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class ObjectMutator(val objectManager: ObjectManager) {
val relation = obj.relation(key)

relation.clear()
for (obj in array) {
val target = if (obj.containsKey("id"))
objectManager.findById(descriptor, (obj["id"] as Number).toLong())!!
for (element in array) {
val target = if (element.containsKey("id"))
objectManager.findById(descriptor, (element["id"] as Number).toLong())!!
else
objectManager.create(descriptor)

relation.add(writeProperties(target, obj))
relation.add(writeProperties(target, element))
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

=== NOW

- default value


=== DONE

- test data?
- default value
- applikation
- maven submodule
- date support in graphql ( scalar )
Expand Down

0 comments on commit 051effe

Please sign in to comment.