Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
edaed415
Commit
edaed415
authored
Nov 04, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
9dec27e7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
125 deletions
+84
-125
ConditionalOnJndi.java
...ework/boot/autoconfigure/condition/ConditionalOnJndi.java
+1
-0
ConditionOnJndiTests.java
...rk/boot/autoconfigure/condition/ConditionOnJndiTests.java
+0
-100
ConditionalOnJndiTests.java
.../boot/autoconfigure/condition/ConditionalOnJndiTests.java
+67
-11
JtaAutoConfigurationTests.java
...ork/boot/autoconfigure/jta/JtaAutoConfigurationTests.java
+3
-3
production-ready-features.adoc
...oot-docs/src/main/asciidoc/production-ready-features.adoc
+11
-11
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+2
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndi.java
View file @
edaed415
...
...
@@ -21,6 +21,7 @@ import java.lang.annotation.ElementType;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
javax.naming.InitialContext
;
import
org.springframework.context.annotation.Conditional
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionOnJndiTests.java
deleted
100644 → 0
View file @
9dec27e7
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
condition
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.Test
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link OnJndiCondition}.
*
* @author Phillip Webb
*/
public
class
ConditionOnJndiTests
{
private
MockableOnJndi
condition
=
new
MockableOnJndi
();
@Test
public
void
jndiNotAvailable
()
{
this
.
condition
.
setJndiAvailable
(
false
);
ConditionOutcome
outcome
=
this
.
condition
.
getMatchOutcome
(
null
,
mockMetaData
());
assertThat
(
outcome
.
isMatch
(),
equalTo
(
false
));
}
@Test
public
void
jndiLocationNotFound
()
{
ConditionOutcome
outcome
=
this
.
condition
.
getMatchOutcome
(
null
,
mockMetaData
(
"java:/a"
));
assertThat
(
outcome
.
isMatch
(),
equalTo
(
false
));
}
@Test
public
void
jndiLocationFound
()
{
this
.
condition
.
setFoundLocation
(
"java:/b"
);
ConditionOutcome
outcome
=
this
.
condition
.
getMatchOutcome
(
null
,
mockMetaData
(
"java:/a"
,
"java:/b"
));
assertThat
(
outcome
.
isMatch
(),
equalTo
(
true
));
}
private
AnnotatedTypeMetadata
mockMetaData
(
String
...
value
)
{
AnnotatedTypeMetadata
metadata
=
mock
(
AnnotatedTypeMetadata
.
class
);
Map
<
String
,
Object
>
attributes
=
new
HashMap
<
String
,
Object
>();
attributes
.
put
(
"value"
,
value
);
given
(
metadata
.
getAnnotationAttributes
(
ConditionalOnJndi
.
class
.
getName
()))
.
willReturn
(
attributes
);
return
metadata
;
}
private
static
class
MockableOnJndi
extends
OnJndiCondition
{
private
boolean
jndiAvailable
=
true
;
private
String
foundLocation
;
@Override
protected
boolean
isJndiAvailable
()
{
return
this
.
jndiAvailable
;
}
@Override
protected
JndiLocator
getJndiLocator
(
String
[]
locations
)
{
return
new
JndiLocator
(
locations
)
{
@Override
public
String
lookupFirstLocation
()
{
return
MockableOnJndi
.
this
.
foundLocation
;
}
};
}
public
void
setJndiAvailable
(
boolean
jndiAvailable
)
{
this
.
jndiAvailable
=
jndiAvailable
;
}
public
void
setFoundLocation
(
String
foundLocation
)
{
this
.
foundLocation
=
foundLocation
;
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJndiTests.java
View file @
edaed415
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.condition;
import
java.util.HashMap
;
import
java.util.Hashtable
;
import
java.util.Map
;
import
javax.naming.Context
;
import
javax.naming.InitialContext
;
import
javax.naming.NamingException
;
...
...
@@ -27,21 +28,25 @@ import javax.naming.spi.InitialContextFactory;
import
org.hamcrest.Matcher
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
iterableWithSize
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link ConditionalOnJndi}
*
* @author Stephane Nicoll
* @author Phillip Webb
*/
public
class
ConditionalOnJndiTests
{
...
...
@@ -49,11 +54,14 @@ public class ConditionalOnJndiTests {
private
ConfigurableApplicationContext
context
;
private
MockableOnJndi
condition
=
new
MockableOnJndi
();
@After
public
void
close
()
{
TestableInitialContextFactory
.
clearAll
();
if
(
this
.
initialContextFactory
!=
null
)
{
System
.
setProperty
(
Context
.
INITIAL_CONTEXT_FACTORY
,
this
.
initialContextFactory
);
System
.
setProperty
(
Context
.
INITIAL_CONTEXT_FACTORY
,
this
.
initialContextFactory
);
}
else
{
System
.
clearProperty
(
Context
.
INITIAL_CONTEXT_FACTORY
);
...
...
@@ -91,13 +99,27 @@ public class ConditionalOnJndiTests {
assertPresent
(
true
);
}
@Test
public
void
jndiLocationNotFound
()
{
ConditionOutcome
outcome
=
this
.
condition
.
getMatchOutcome
(
null
,
mockMetaData
(
"java:/a"
));
assertThat
(
outcome
.
isMatch
(),
equalTo
(
false
));
}
@Test
public
void
jndiLocationFound
()
{
this
.
condition
.
setFoundLocation
(
"java:/b"
);
ConditionOutcome
outcome
=
this
.
condition
.
getMatchOutcome
(
null
,
mockMetaData
(
"java:/a"
,
"java:/b"
));
assertThat
(
outcome
.
isMatch
(),
equalTo
(
true
));
}
private
void
setupJndi
()
{
this
.
initialContextFactory
=
System
.
getProperty
(
Context
.
INITIAL_CONTEXT_FACTORY
);
System
.
setProperty
(
Context
.
INITIAL_CONTEXT_FACTORY
,
TestableInitialContextFactory
.
class
.
getName
());
}
private
void
assertPresent
(
boolean
expected
)
{
int
expectedNumber
=
expected
?
1
:
0
;
Matcher
<
Iterable
<
String
>>
matcher
=
iterableWithSize
(
expectedNumber
);
...
...
@@ -113,6 +135,15 @@ public class ConditionalOnJndiTests {
this
.
context
=
applicationContext
;
}
private
AnnotatedTypeMetadata
mockMetaData
(
String
...
value
)
{
AnnotatedTypeMetadata
metadata
=
mock
(
AnnotatedTypeMetadata
.
class
);
Map
<
String
,
Object
>
attributes
=
new
HashMap
<
String
,
Object
>();
attributes
.
put
(
"value"
,
value
);
given
(
metadata
.
getAnnotationAttributes
(
ConditionalOnJndi
.
class
.
getName
()))
.
willReturn
(
attributes
);
return
metadata
;
}
@Configuration
@ConditionalOnJndi
static
class
JndiAvailableConfiguration
{
...
...
@@ -133,11 +164,37 @@ public class ConditionalOnJndiTests {
}
}
private
static
class
MockableOnJndi
extends
OnJndiCondition
{
private
boolean
jndiAvailable
=
true
;
private
String
foundLocation
;
@Override
protected
boolean
isJndiAvailable
()
{
return
this
.
jndiAvailable
;
}
@Override
protected
JndiLocator
getJndiLocator
(
String
[]
locations
)
{
return
new
JndiLocator
(
locations
)
{
@Override
public
String
lookupFirstLocation
()
{
return
MockableOnJndi
.
this
.
foundLocation
;
}
};
}
public
void
setFoundLocation
(
String
foundLocation
)
{
this
.
foundLocation
=
foundLocation
;
}
}
public
static
class
TestableInitialContextFactory
implements
InitialContextFactory
{
private
static
TestableContext
context
;
@Override
public
Context
getInitialContext
(
Hashtable
<?,
?>
environment
)
throws
NamingException
{
return
getContext
();
...
...
@@ -147,8 +204,8 @@ public class ConditionalOnJndiTests {
try
{
getContext
().
bind
(
name
,
obj
);
}
catch
(
NamingException
o_O
)
{
throw
new
IllegalStateException
(
o_O
);
catch
(
NamingException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
...
...
@@ -161,14 +218,13 @@ public class ConditionalOnJndiTests {
try
{
context
=
new
TestableContext
();
}
catch
(
NamingException
o_O
)
{
throw
new
IllegalStateException
(
o_O
);
catch
(
NamingException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
return
context
;
}
private
static
class
TestableContext
extends
InitialContext
{
private
final
Map
<
String
,
Object
>
bindings
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -178,8 +234,7 @@ public class ConditionalOnJndiTests {
}
@Override
public
void
bind
(
String
name
,
Object
obj
)
throws
NamingException
{
public
void
bind
(
String
name
,
Object
obj
)
throws
NamingException
{
this
.
bindings
.
put
(
name
,
obj
);
}
...
...
@@ -190,7 +245,8 @@ public class ConditionalOnJndiTests {
@Override
public
Hashtable
<?,
?>
getEnvironment
()
throws
NamingException
{
return
new
Hashtable
<
Object
,
Object
>();
// Used to detect if JNDI is available
return
new
Hashtable
<
Object
,
Object
>();
// Used to detect if JNDI is
// available
}
public
void
clearAll
()
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jta/JtaAutoConfigurationTests.java
View file @
edaed415
...
...
@@ -91,13 +91,13 @@ public class JtaAutoConfigurationTests {
@Test
public
void
disableJtaSupport
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.jta.enabled:false"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.jta.enabled:false"
);
this
.
context
.
register
(
JtaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
0
,
this
.
context
.
getBeansOfType
(
JtaTransactionManager
.
class
).
size
());
assertEquals
(
0
,
this
.
context
.
getBeansOfType
(
XADataSourceWrapper
.
class
).
size
());
assertEquals
(
0
,
this
.
context
.
getBeansOfType
(
XAConnectionFactoryWrapper
.
class
).
size
());
assertEquals
(
0
,
this
.
context
.
getBeansOfType
(
XAConnectionFactoryWrapper
.
class
)
.
size
());
}
@Test
...
...
spring-boot-docs/src/main/asciidoc/production-ready-features.adoc
View file @
edaed415
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
edaed415
...
...
@@ -913,6 +913,8 @@ If you need to add or customize converters you can use Spring Boot's
Any `HttpMessageConverter` bean that is present in the context will be added to the list of
converters. You can also override default converters that way.
[[boot-features-spring-message-codes]]
==== MessageCodesResolver
Spring MVC has a strategy for generating error codes for rendering error messages
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment